#Spell system and FfH specific callout python functions
#All code by Kael, all bugs by woodelf

from CvPythonExtensions import *
import CvUtil
import Popup as PyPopup
import CvScreensInterface
import sys
import PyHelpers
import CustomFunctions
import ScenarioFunctions
import math

#### EXPANDED MERCENARIES - westamastaflash - 08/03/2008 ####
import MercenaryFunctions
import RandomMercenaryList
import CvMercenaryChooser
#### END EXPANDED MERCENARIES SECTION ####

PyInfo = PyHelpers.PyInfo
PyPlayer = PyHelpers.PyPlayer
gc = CyGlobalContext()
cf = CustomFunctions.CustomFunctions()
sf = ScenarioFunctions.ScenarioFunctions()

#### EXPANDED MERCENARIES - westamastaflash - 08/03/2008 ####
mf = MercenaryFunctions.MercenaryFunctions()
#### END EXPANDED MERCENARIES SECTION ####

def cast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	eval(spell.getPyResult())

def canCast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	return eval(spell.getPyRequirement())

def effect(argsList):
	pCaster, eProm = argsList
	prom = gc.getPromotionInfo(eProm)
	eval(prom.getPyPerTurn())

def postPromotionCombatLost(argsList):
	pCaster, pOpponent, eProm = argsList
	prom = gc.getPromotionInfo(eProm)
	eval(prom.getPyPostCombatLost())

def postPromotionCombatWon(argsList):
	pCaster, pOpponent, eProm = argsList
	prom = gc.getPromotionInfo(eProm)
	eval(prom.getPyPostCombatWon())

def postDeath(argsList):
	pCaster, eKiller, eUnit = argsList
	pKiller = gc.getPlayer(eKiller)
	unit = gc.getUnitInfo(eUnit)
	eval(unit.getPyDeath())

def promotionRemove(argsList):
	pCaster, ePromotion = argsList
	promotion = gc.getPromotionInfo(ePromotion)
	return eval(promotion.getPyOnRemove())


def atRange(argsList):
	pCaster, pPlot, eImp = argsList
	imp = gc.getImprovementInfo(eImp)
	eval(imp.getPythonAtRange())

def onMove(argsList):
	pCaster, pPlot, eImp = argsList
	imp = gc.getImprovementInfo(eImp)
	eval(imp.getPythonOnMove())

def onMoveFeature(argsList):
	pCaster, pPlot, eFeature = argsList
	feature = gc.getFeatureInfo(eFeature)
	eval(feature.getPythonOnMove())

def vote(argsList):
	eVote, int = argsList
	vote = gc.getVoteInfo(eVote)
	eval(vote.getPyResult())

def miscast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	eval(spell.getPyMiscast())

def globalAnnounce(argsList):
	unit, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	player = PyPlayer(unit.getOwner())
	if gc.getGame().getAIAutoPlay() == 0:
		activePlayer = gc.getPlayer(gc.getGame().getActivePlayer())
		sPlayerName = player.getName()
		sSpellName = spell.getDescription()
		sQuote = spell.getQuote()
		sPopupText = CyTranslator().getText('TXT_KEY_MISC_SPELL_POPUP',(sPlayerName, sSpellName, sQuote))
		cf.addPopup(sPopupText, str(gc.getLeaderHeadInfo(player.getLeaderType()).getImage()))

def postCombatLost(argsList):
	pCaster, pOpponent = argsList
	unit = gc.getUnitInfo(pCaster.getUnitType())
	eval(unit.getPyPostCombatLost())

def postCombatWon(argsList):
	pCaster, pOpponent = argsList
	unit = gc.getUnitInfo(pCaster.getUnitType())
	eval(unit.getPyPostCombatWon())

def findClearPlot(pUnit, plot):
	BestPlot = -1
	iBestPlot = 0
	if pUnit == -1:
		iX = plot.getX()
		iY = plot.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				iCurrentPlot = 0
				pPlot = CyMap().plot(iiX,iiY)
				if pPlot.getNumUnits() == 0:
					if (pPlot.isWater() == plot.isWater() and pPlot.isPeak() == False and pPlot.isCity() == False):
						iCurrentPlot = iCurrentPlot + 5
				if iCurrentPlot >= 1:
					iCurrentPlot = iCurrentPlot + CyGame().getSorenRandNum(5, "findClearPlot")
					if iCurrentPlot >= iBestPlot:
						BestPlot = pPlot
						iBestPlot = iCurrentPlot
		return BestPlot
	iX = pUnit.getX()
	iY = pUnit.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			iCurrentPlot = 0
			pPlot = CyMap().plot(iiX,iiY)
			if pPlot.getNumUnits() == 0:
				if pUnit.canMoveOrAttackInto(pPlot, False):
					iCurrentPlot = iCurrentPlot + 5
			for i in range(pPlot.getNumUnits()):
				if pPlot.getUnit(i).getOwner() == pUnit.getOwner():
					if pUnit.canMoveOrAttackInto(pPlot, False):
						iCurrentPlot = iCurrentPlot + 15
			if pPlot.isCity():
				if pPlot.getPlotCity().getOwner() == pUnit.getOwner():
					iCurrentPlot = iCurrentPlot + 50
			if (iX == iiX and iY == iiY):
				iCurrentPlot = 0
			if iCurrentPlot >= 1:
				iCurrentPlot = iCurrentPlot + CyGame().getSorenRandNum(5, "findClearPlot")
				if iCurrentPlot >= iBestPlot:
					BestPlot = pPlot
					iBestPlot = iCurrentPlot
	return BestPlot

def postCombatConsumePaladin(pCaster, pOpponent):
	if (pOpponent.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_PALADIN')):
		pCaster.setDamage(0, pCaster.getOwner())
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CONSUME_PALADIN", ()),'',1,'Art/Interface/Buttons/Units/Beast of Agares.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)

def postCombatDonal(pCaster, pOpponent):
	if (pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON')) or pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD'))):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RECRUITER'), True)

def postCombatExplode(pCaster, pOpponent):
	iX = pCaster.getX()
	iY = pCaster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			if not (iiX == iX and iiY == iY):
				pPlot = CyMap().plot(iiX,iiY)
				if pPlot.isNone() == False:
					if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
						if CyGame().getSorenRandNum(100, "Flames Spread") <= gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
							bValid = True
							iImprovement = pPlot.getImprovementType()
							if iImprovement != -1 :
								if gc.getImprovementInfo(iImprovement).isPermanent() :
									bValid = False
							if bValid:
								pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
					for i in range(pPlot.getNumUnits()):
						pUnit = pPlot.getUnit(i)
						pUnit.doDamage(10, 100, pCaster, gc.getInfoTypeForString('DAMAGE_FIRE'), false)

def postCombatHeal50(pCaster, pOpponent):
	if pCaster.getDamage() > 0:
		pCaster.setDamage(pCaster.getDamage() / 2, pCaster.getOwner())

def postCombatIra(pCaster, pOpponent):
	if pOpponent.isAlive():
		if pCaster.baseCombatStr() < 32:
			pCaster.setBaseCombatStr(pCaster.baseCombatStr() - 3)
			pCaster.setBaseCombatStrDefense(pCaster.baseCombatStrDefense() - 3)

def postCombatMimic(pCaster, pOpponent):
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
	iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE')
	iGreatCommander = gc.getInfoTypeForString('PROMOTION_GREAT_COMMANDER')
	iLeader = gc.getInfoTypeForString('PROMOTION_LEADER')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	listProms = []
	iCount = 0
	for iProm in range(gc.getNumPromotionInfos()):
		if pCaster.isHasPromotion(iProm):
			iCount += 1
		else:
			if (pOpponent.isHasPromotion(iProm)):
				if gc.getPromotionInfo(iProm).isEquipment() == False:
					if (iProm != iChanneling3 and iProm != iDivine and iProm != iBronze and iProm != iIron and iProm != iMithril and iProm != iGreatCommander and iProm != iLeader):
						if gc.getPromotionInfo(iProm).isRace() == false:
							listProms.append(iProm)
	if len(listProms) > 0:
		iCount += 1
		iRnd = CyGame().getSorenRandNum(len(listProms), "Mimic")
		pCaster.setHasPromotion(listProms[iRnd], True)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_PROMOTION_STOLEN", ()),'',1,gc.getPromotionInfo(listProms[iRnd]).getButton(),ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if iCount >= 20:
		pPlayer = gc.getPlayer(pCaster.getOwner())
		if pPlayer.isHuman():
			t = "TROPHY_FEAT_MIMIC_20"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

def postCombatAcheron(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_ACHERON"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatArs(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_ARS"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatAuricAscendedLost(pCaster, pOpponent):
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	for iTrait in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(iTrait):
			pPlayer.setHasTrait(iTrait, False)
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GODSLAYER')):
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			t = "TROPHY_FEAT_GODSLAYER"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

def postCombatAuricAscendedWon(pCaster, pOpponent):
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GODSLAYER')):
		iPlayer = pCaster.getOwner()
		pPlayer = gc.getPlayer(iPlayer)
		for iTrait in range(gc.getNumTraitInfos()):
			if pPlayer.hasTrait(iTrait):
				pPlayer.setHasTrait(iTrait, False)
		pCaster.kill(True, pOpponent.getOwner())
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			t = "TROPHY_FEAT_GODSLAYER"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

def postCombatBasium(pCaster, pOpponent):
	if not pCaster.isImmortal():
		iPlayer = pCaster.getOwner()
		pPlayer = gc.getPlayer(iPlayer)
		for iTrait in range(gc.getNumTraitInfos()):
			if pPlayer.hasTrait(iTrait):
				pPlayer.setHasTrait(iTrait, False)
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			t = "TROPHY_DEFEATED_BASIUM"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

def postCombatBuboes(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_BUBOES"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatHyborem(pCaster, pOpponent):
	if not pCaster.isImmortal():
		iPlayer = pCaster.getOwner()
		pPlayer = gc.getPlayer(iPlayer)
		for iTrait in range(gc.getNumTraitInfos()):
			if iTrait != gc.getInfoTypeForString('TRAIT_FALLOW'):
				if pPlayer.hasTrait(iTrait):
					pPlayer.setHasTrait(iTrait, False)
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			t = "TROPHY_DEFEATED_HYBOREM"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

def postCombatLeviathan(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_LEVIATHAN"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatOrthus(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_ORTHUS"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatStephanos(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_STEPHANOS"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatTreant(pCaster, pOpponent):
	pPlot = pCaster.plot()
	if pPlot.getFeatureType() == -1:
		if pPlot.canHaveFeature(gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST_NEW'), 0)

def postCombatYersinia(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_YERSINIA"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatReduceCombat1(pCaster, pOpponent):
	if pOpponent.isAlive():
		if pCaster.baseCombatStr() > 5:
			pCaster.setBaseCombatStr(pCaster.baseCombatStr() - 5)
			pCaster.setBaseCombatStrDefense(pCaster.baseCombatStrDefense() - 5)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_STRENGTH_REDUCED", ()),'',1,'Art/Interface/Buttons/Units/Repentant Angel.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)

def postCombatReducePopulation(pCaster, pOpponent):
	pPlot = pOpponent.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getPopulation() > 1:
			pCity.changePopulation(-1)
			CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POPULATION_REDUCED", ()),'',1,'Art/Interface/Buttons/Units/Angel of Death.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)

def postCombatLostSailorsDirge(pCaster, pOpponent):
	iPlayer = pOpponent.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_SAILORS_DIRGE_DEFEATED')
	triggerData = pPlayer.initTriggeredData(iEvent, true, -1, pCaster.getX(), pCaster.getY(), iPlayer, -1, -1, -1, -1, -1)

def postCombatSplit(pCaster, pOpponent):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK')) == False:
		pPlayer = gc.getPlayer(pCaster.getOwner())
		iUnit = pCaster.getUnitType()
		newUnit = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit2 = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
		newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
		newUnit.setDamage(25, -1)
		newUnit2.setDamage(25, -1)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG')) == False:
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
			newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
		newUnit.setDuration(pCaster.getDuration())
		newUnit2.setDuration(pCaster.getDuration())
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SPLIT", ()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)

def postCombatWolfRider(pCaster, pOpponent):
	if (pOpponent.getUnitType() == gc.getInfoTypeForString('UNIT_WOLF') or pOpponent.getUnitType() == gc.getInfoTypeForString('UNIT_WARG')):
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WOLF_RIDER", ()),'',1,'Art/Interface/Buttons/Units/Wolf Rider.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
		pPlayer = gc.getPlayer(pCaster.getOwner())
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WOLF_RIDER'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(pCaster)

def reqAddToFleshGolem(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL')):
		return false
	#### EXPANDED MERCENARIES - westamastaflash - 08/03/2008 ####
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GUILD_MERCENARY')):
		return false
	#### END EXPANDED MERCENARIES SECTION ####
	if caster.isImmuneToMagic():
		return False
	return True

def spellAddToFleshGolem(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iChanneling = gc.getInfoTypeForString('PROMOTION_CHANNELING')
	iChanneling2 = gc.getInfoTypeForString('PROMOTION_CHANNELING2')
	iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
	iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE')
	iDivine2 = gc.getInfoTypeForString('PROMOTION_DIVINE2')
	iFleshGolem = gc.getInfoTypeForString('UNITCLASS_FLESH_GOLEM')
	pFleshGolem = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iFleshGolem):
			pFleshGolem = pUnit
	if pFleshGolem != -1:
		if caster.baseCombatStr() > pFleshGolem.baseCombatStr():
			pFleshGolem.setBaseCombatStr(pFleshGolem.baseCombatStr() + 1)
		if caster.baseCombatStrDefense() > pFleshGolem.baseCombatStrDefense():
			pFleshGolem.setBaseCombatStrDefense(pFleshGolem.baseCombatStrDefense() + 1)
		for iCount in range(gc.getNumPromotionInfos()):
			if (caster.isHasPromotion(iCount)):
				if (iCount != iChanneling and iCount != iChanneling2 and iCount != iChanneling3 and iCount != iDivine and iCount != iDivine2):
					if not gc.getPromotionInfo(iCount).isRace():
						if gc.getPromotionInfo(iCount).getBonusPrereq() == -1:
							if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling2:
								if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling3:
									if gc.getPromotionInfo(iCount).isEquipment() == False:
										pFleshGolem.setHasPromotion(iCount, true)
		if pFleshGolem.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')):
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS'), False)
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS'), False)
		if pFleshGolem.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')):
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS'), False)
		if pFleshGolem.baseCombatStr() >= 15:
			if pPlayer.isHuman():
				t = "TROPHY_FEAT_FLESH_GOLEM_15"
				if not CyGame().isHasTrophy(t):
					CyGame().changeTrophyValue(t, 1)

def reqAddToFreakShowHuman(caster):
	if caster.getRace() != -1:
		return False
	return True

def reqArcaneLacuna(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	manaTypes = [ 'BONUS_MANA_AIR','BONUS_MANA_BODY','BONUS_MANA_CHAOS','BONUS_MANA_DEATH','BONUS_MANA_EARTH','BONUS_MANA_ENCHANTMENT','BONUS_MANA_ENTROPY','BONUS_MANA_FIRE','BONUS_MANA_LAW','BONUS_MANA_LIFE','BONUS_MANA_METAMAGIC','BONUS_MANA_MIND','BONUS_MANA_NATURE','BONUS_MANA_SHADOW','BONUS_MANA_SPIRIT','BONUS_MANA_SUN','BONUS_MANA_WATER' ]
	iCount = 0
	for szBonus in manaTypes:
		iBonus = gc.getInfoTypeForString(szBonus)
		iCount += CyMap().getNumBonuses(iBonus)
	if iCount == 0:
		return False
	if pPlayer.isHuman() == False:
		if iCount < 7:
			return False
	return True

def spellArcaneLacuna(caster):
	manaTypes = [ 'BONUS_MANA_AIR','BONUS_MANA_BODY','BONUS_MANA_CHAOS','BONUS_MANA_DEATH','BONUS_MANA_EARTH','BONUS_MANA_ENCHANTMENT','BONUS_MANA_ENTROPY','BONUS_MANA_FIRE','BONUS_MANA_LAW','BONUS_MANA_LIFE','BONUS_MANA_METAMAGIC','BONUS_MANA_MIND','BONUS_MANA_NATURE','BONUS_MANA_SHADOW','BONUS_MANA_SPIRIT','BONUS_MANA_SUN','BONUS_MANA_WATER' ]
	iAdept = gc.getInfoTypeForString('UNITCOMBAT_ADEPT')
	iCount = 0
	pPlayer = gc.getPlayer(caster.getOwner())
	for szBonus in manaTypes:
		iBonus = gc.getInfoTypeForString(szBonus)
		iCount += CyMap().getNumBonuses(iBonus)
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.getUnitCombatType() == iAdept:
			pUnit.changeExperience(iCount, -1, False, False, False, False)
	iDelay = 20
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
		iDelay = 14
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
		iDelay = 30
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
		iDelay = 60
	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		pPlayer2 = gc.getPlayer(iPlayer2)
		if pPlayer2.isAlive():
			if pPlayer2.getTeam() != pPlayer.getTeam():
				pPlayer2.changeDisableSpellcasting(iDelay)

def reqArdor(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getGreatPeopleCreated() == 0:
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getGreatPeopleCreated() < 5:
			return False
	return True

def spellArdor(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.setGreatPeopleCreated(0)
	pPlayer.setGreatPeopleThresholdModifier(0)

def reqArenaBattle(caster):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_MELEE'):
		return True
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_RECON'):
		return True
	if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE'):
		return True
	return False

def spellArenaBattle(caster):
	pCity = caster.plot().getPlotCity()
	pCity.changeHappinessTimer(3)
	if CyGame().getSorenRandNum(100, "Arena Battle") < 50:
		caster.changeExperience(CyGame().getSorenRandNum(6, "Arena Battle") + 1, -1, False, False, False, False)
		caster.setDamage(25, caster.getOwner())
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_WIN", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
		if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE'):
			pPlayer = gc.getPlayer(caster.getOwner())
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARRIOR'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(caster)
	else:
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_LOSE", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
		caster.kill(True, PlayerTypes.NO_PLAYER)

def reqCallBlizzard(caster):
	iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
	pPlot = caster.plot()
	if pPlot.getFeatureType() == iBlizzard:
		return False
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT'):
		return False
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if pPlot.getFeatureType() == iBlizzard:
				return True
	return False

def spellCallBlizzard(caster):
	iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
	iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
	iX = caster.getX()
	iY = caster.getY()
	pBlizPlot = -1
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if pPlot.getFeatureType() == iBlizzard:
				pBlizPlot = pPlot
	if pBlizPlot != -1:
		pBlizPlot.setFeatureType(-1, -1)
	pPlot = caster.plot()
	pPlot.setFeatureType(iBlizzard, 0)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		pPlot.setTerrainType(iTundra,True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(iTundra,True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT'):
		pPlot.setTerrainType(iTundra,True,True)

def reqCallOfTheGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iX = caster.getX()
	iY = caster.getY()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iGraveyard = gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				p2Player = gc.getPlayer(pUnit.getOwner())
				e2Team = p2Player.getTeam()
				if eTeam.isAtWar(e2Team) == True:
					return True
				if pUnit.getRace() == iUndead:
					if pUnit.getDamage() != 0:
						return True
				if pPlot.getImprovementType() == iGraveyard:
					return True
	return False

def spellCallOfTheGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iX = caster.getX()
	iY = caster.getY()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iGraveyard = gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			bValid = False
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				p2Player = gc.getPlayer(pUnit.getOwner())
				e2Team = p2Player.getTeam()
				if eTeam.isAtWar(e2Team) == True:
					pUnit.doDamage(40, 100, caster, gc.getInfoTypeForString('DAMAGE_DEATH'), true)
					bValid = True
				else:
					if pUnit.getRace() == iUndead:
						if pUnit.getDamage() != 0:
							pUnit.setDamage(0, caster.getOwner())
				if pPlot.getImprovementType() == iGraveyard:
					pPlot.setImprovementType(-1)
					pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					bValid = True
			if bValid:
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SACRIFICE'),pPlot.getPoint())

def reqCommanderJoin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GREAT_COMMANDER')):
		return False
	iCommander = gc.getInfoTypeForString('UNITCLASS_COMMANDER')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iCommander):
			pCommander = pUnit
	if pCommander == -1:
		return False
	if pCommander.isHasCasted():
		return False
	if pPlayer.isHuman() == False:
		if caster.baseCombatStr() <= 5:
			return False
	return True

def spellCommanderJoin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iCommander = gc.getInfoTypeForString('UNITCLASS_COMMANDER')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iCommander):
			pCommander = pUnit
	if pCommander != -1:
		pCommander.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)
		pCommander.kill(False, PlayerTypes.NO_PLAYER)

def spellCommanderJoinDecius(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iDecius = gc.getInfoTypeForString('UNIT_DECIUS')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iDecius):
			pCommander = pUnit
	if pCommander != -1:
		caster.setScenarioCounter(iDecius)
		pCommander.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)
		pCommander.kill(False, PlayerTypes.NO_PLAYER)

def spellCommanderSplit(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iCommander = gc.getInfoTypeForString('UNIT_COMMANDER')
	if caster.getScenarioCounter() == gc.getInfoTypeForString('UNIT_DECIUS'):
		iCommander = gc.getInfoTypeForString('UNIT_DECIUS')
		caster.setScenarioCounter(-1)
	newUnit = pPlayer.initUnit(iCommander, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def reqConvertCityBasium(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	return True

def spellConvertCityBasium(caster):
	pCity = caster.plot().getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer.acquireCity(pCity,false,false)
	pCity = caster.plot().getPlotCity()
	pCity.changeCulture(iPlayer, 300, True)

def reqConvertCityRantine(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	if pCity.getOwner() != gc.getORC_PLAYER():
		return False
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getOwner() == gc.getORC_PLAYER():
			if pUnit.baseCombatStr() > caster.baseCombatStr():
				return False
	return True

def spellConvertCityRantine(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.acquireCity(pCity,false,false)

def reqCreateDenBear(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_BEAR_DEN')
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenBear(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_BEAR_DEN')
	iUnit = gc.getInfoTypeForString('UNIT_BEAR')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenLion(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_LION_DEN')
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenLion(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_LION_DEN')
	iUnit = gc.getInfoTypeForString('UNIT_LION')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCrewBuccaneers(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BUCCANEERS')):
		return False
	if caster.maxMoves() <= 1:
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == false:
		iUnit = caster.getUnitType()
		if (iUnit != gc.getInfoTypeForString('UNIT_FRIGATE') and iUnit != gc.getInfoTypeForString('UNIT_MAN_O_WAR')):
			return false
	return true

def reqCrewLongshoremen(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LONGSHOREMEN')):
		return False
#	if (PyInfo.UnitInfo(caster.getUnitType()).getCargoSpace() == 0 and caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXPANDED_HULL')) == False):
#		return False
	if caster.cargoSpaceAvailable(-1, gc.getInfoTypeForString('DOMAIN_LAND')) == 0:
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == false:
		iUnit = caster.getUnitType()
		if (iUnit != gc.getInfoTypeForString('UNIT_GALLEY') and iUnit != gc.getInfoTypeForString('UNIT_CARAVEL')):
			return false
	return True

def reqCrewNormalCrew(caster):
	pPlot = caster.plot()
	if (caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BUCCANEERS')) == False and caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SKELETON_CREW')) == False and caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LONGSHOREMEN')) == False):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		return False
	return True

def reqCrewSkeletonCrew(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SKELETON_CREW')):
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == false:
		iUnit = caster.getUnitType()
		if (iUnit != gc.getInfoTypeForString('UNIT_QUEEN_OF_THE_LINE') and iUnit != gc.getInfoTypeForString('UNIT_TRIREME') and iUnit != gc.getInfoTypeForString('UNIT_GALLEON')):
			return false
	return True

def effectCrownOfBrillance(caster):
	caster.cast(gc.getInfoTypeForString('SPELL_CROWN_OF_BRILLANCE'))

def reqCrownOfBrillance(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CROWN_OF_BRILLANCE')):
		return False
	return True

def reqCrush(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			bEnemy = false
			bNeutral = false
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					bEnemy = true
				else:
					bNeutral = true
			if (bEnemy and bNeutral == false):
				return true
	return false

def spellCrush(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iBestValue = 0
	pBestPlot = -1
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			bNeutral = false
			iValue = 0
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					iValue = iValue + 10
				else:
					bNeutral = true
			if (iValue > iBestValue and bNeutral == false):
				iBestValue = iValue
				pBestPlot = pPlot
	if pBestPlot != -1:
		for i in range(pBestPlot.getNumUnits()):
			pUnit = pBestPlot.getUnit(i)
			pUnit.doDamage(50, 75, caster, gc.getInfoTypeForString('DAMAGE_PHYSICAL'), true)
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_CRUSH'),pBestPlot.getPoint())

def reqExorcism(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if (pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_UNDEAD') or pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_DEMON')):
					if pPlayer.isHuman():
						return True
					p2Player = gc.getPlayer(pUnit.getOwner())
					e2Team = gc.getTeam(p2Player.getTeam())
					if e2Team.isAtWar(eTeam):
						return True
	return False

def spellExorcism(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_UNDEAD'):
					if (pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_DROWN') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_BONE_HORDE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SKELETON') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SPECTRE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_WRAITH')):
						pUnit.doDamage(30, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), true)
					else:
						pUnit.doDamage(15, 50, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), true)
				if pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_DEMON'):
						pUnit.doDamage(15, 80, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), true)


def reqDispelMagic(caster):
	if caster.canDispel(gc.getInfoTypeForString('SPELL_DISPEL_MAGIC')):
		return True
	pPlot = caster.plot()
	if pPlot.getBonusType(-1) != -1:
		if gc.getBonusInfo(pPlot.getBonusType(-1)).getBonusClassType() == gc.getInfoTypeForString('BONUSCLASS_MANA'):
			if pPlot.getImprovementType() == -1:
				return True
			if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
				return True
	return False

def spellDispelMagic(caster):
	pPlot = caster.plot()
	if pPlot.getBonusType(-1) != -1:
		if gc.getBonusInfo(pPlot.getBonusType(-1)).getBonusClassType() == gc.getInfoTypeForString('BONUSCLASS_MANA'):
			if pPlot.getImprovementType() == -1:
				pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA'))
			else:
				if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
					pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA'))
					pPlot.setImprovementType(-1)

def reqDisrupt(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if caster.getTeam() == pCity.getTeam():
		return False
	return True

def spellDisrupt(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iPlayer2 = pCity.getOwner()
	pPlayer2 = gc.getPlayer(iPlayer2)
	pCity.changeHurryAngerTimer(2)
	iRnd = CyGame().getSorenRandNum(3, "Disrupt")
	if iRnd != 0:
		pCity.changeCulture(iPlayer2,-1 * iRnd,True)
	CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DISRUPT_ENEMY",()),'',1,'Art/Interface/Buttons/Spells/Disrupt.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
	CyInterface().addMessage(iPlayer2,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DISRUPT",()),'',1,'Art/Interface/Buttons/Spells/Disrupt.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
	if pCity.getCulture(iPlayer2) < 1:
		pPlayer.acquireCity(pCity,false,false)
		pPlayer2.AI_changeAttitudeExtra(iPlayer,-4)

def reqDivineRetribution(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellDivineRetribution(caster):
	iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iPlayer in range(gc.getMAX_PLAYERS()):
		player = gc.getPlayer(iPlayer)
		if player.isAlive():
			py = PyPlayer(iPlayer)
			for pUnit in py.getUnitList():
				if (pUnit.getRace() == iDemon or pUnit.getRace() == iUndead and pUnit.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_SCIONS')):
					pUnit.doDamage(50, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), false)
				if (pUnit.getRace() == iUndead and pUnit.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SCIONS')):
					if (pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_BONE_HORDE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SKELETON') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SPECTRE') or pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_WRAITH')):
						pUnit.doDamage(50, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), true)
					else:
						pUnit.doDamage(30, 70, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), true)

def reqDomination(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	if pPlayer.isHuman() == false:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.isAlive():
					if not pUnit.isDelayedDeath():
						if eTeam.isAtWar(pUnit.getTeam()):
							iResist = pUnit.getResistChance(caster, gc.getInfoTypeForString('SPELL_DOMINATION'))
							if iResist <= iResistMax:
								return true
	return false

def spellDomination(caster):
	iSpell = gc.getInfoTypeForString('SPELL_DOMINATION')
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	iBestValue = 0
	pBestUnit = -1
	if pPlayer.isHuman() == false:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				iValue = 0
				if pUnit.isAlive():
					if pUnit.isDelayedDeath() == False:
						if eTeam.isAtWar(pUnit.getTeam()):
							iResist = pUnit.getResistChance(caster, iSpell)
							if iResist <= iResistMax:
								iValue = pUnit.baseCombatStr() * 10
								iValue = iValue + (100 - iResist)
								if iValue > iBestValue:
									iBestValue = iValue
									pBestUnit = pUnit
	if pBestUnit != -1:
		pPlot = caster.plot()
		if pBestUnit.isResisted(caster, iSpell) == false:
			CyInterface().addMessage(pBestUnit.getOwner(),true,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(7),pBestUnit.getX(),pBestUnit.getY(),True,True)
			CyInterface().addMessage(caster.getOwner(),true,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION_ENEMY", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			newUnit = pPlayer.initUnit(pBestUnit.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(pBestUnit)
			newUnit.changeImmobileTimer(1)
		else:
			CyInterface().addMessage(caster.getOwner(),true,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION_FAILED", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND3'), False)

def reqEarthquake(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		eTeam = pPlayer.getTeam()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				p2Player = gc.getPlayer(pPlot.getOwner())
				if pPlot.isOwned():
					e2Team = gc.getTeam(p2Player.getTeam())
					if e2Team.isAtWar(eTeam) == False:
						return False
	return True

def spellEarthquake(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if (pPlot.isCity() or pPlot.getImprovementType() != -1):
					if pPlot.isOwned():
						cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
				if pPlot.isCity():
					pCity = pPlot.getPlotCity()
					for i in range(gc.getNumBuildingInfos()):
						iRnd = CyGame().getSorenRandNum(100, "Bob")
						if (gc.getBuildingInfo(i).getConquestProbability() != 100 and iRnd <= 25):
							pCity.setNumRealBuilding(i, 0)
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if pUnit.isFlying() == False:
						pUnit.setFortifyTurns(0)
				iRnd = CyGame().getSorenRandNum(100, "Bob")
				if iRnd <= 25:
					iImprovement = pPlot.getImprovementType()
					if iImprovement != -1:
						if gc.getImprovementInfo(iImprovement).isPermanent() == False:
							pPlot.setImprovementType(-1)

def spellEnterPortal(caster):
	pPlot = caster.plot()
	iX = pPlot.getPortalExitX()
	iY = pPlot.getPortalExitY()
	pExitPlot = CyMap().plot(iX,iY)
	if not pPlot.isNone():
		caster.setXY(iX, iY, false, true, true)

def spellEntertain(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	iPlayer2 = pCity.getOwner()
	if iPlayer != iPlayer2:
		pPlayer = gc.getPlayer(iPlayer)
		pPlayer2 = gc.getPlayer(iPlayer2)
		iGold = (pCity.getPopulation() / 2) + 1
		pPlayer.changeGold(iGold)
		szBuffer = CyTranslator().getText("TXT_KEY_MESSAGE_ENTERTAIN_GOOD", (iGold, ))
		CyInterface().addMessage(iPlayer,true,25,szBuffer,'',1,'Art/Interface/Buttons/Spells/Entertain.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
		iGold = iGold * -1
		pPlayer2.changeGold(iGold)
		szBuffer = CyTranslator().getText("TXT_KEY_MESSAGE_ENTERTAIN_BAD", (iGold, ))
		CyInterface().addMessage(iPlayer2,true,25,szBuffer,'',1,'Art/Interface/Buttons/Spells/Entertain.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
	pCity.changeHappinessTimer(2)

def reqEscape(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if caster.getDamage() >= 50:
			return False
	return True

def reqExploreLair(caster):
	if caster.isOnlyDefensive():
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
		return False
	if caster.isBarbarian():
		return False
	if caster.getDuration() > 0:
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_BIRD'):
		return False
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlot.isWater():
		eBarbCiv = gc.getImprovementInfo(pPlot.getImprovementType()).getSpawnUnitCiv()
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getCivilizationType() == eBarbCiv:
				return False
		if not pPlayer.isHuman():
			pCapital = pPlayer.getCapitalCity()
			if pCapital.isNone():
				return False
			elif (plotDistance(caster.getX(), caster.getY(), pCapital.getX(), pCapital.getY()) < 20):
				if (pCapital.plot().getNumDefenders(caster.getOwner()) < 4):
					return False
			else:
				pNearestCity = gc.getMap().findCity(caster.getX(), caster.getY(), -1, caster.getTeam(), False, False, -1, -1, pCapital)
				if not pNearestCity.isNone():
					if (plotDistance(caster.getX(), caster.getY(), pNearestCity.getX(), pNearestCity.getY()) < 10):
						if (pNearestCity.plot().getNumDefenders(caster.getOwner()) < 2):
							return False
	return True

def spellExploreLair(caster):
	pPlot = caster.plot()
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair") + caster.getLevel()
	iDestroyLair = 0
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	if caster.isHasPromotion(iAdventurer):
		iRnd += 10

	if iRnd < 10:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 10 and iRnd < 30:
		iDestroyLair = cf.exploreLairBad(caster)
	if iRnd >= 30 and iRnd < 60:
		iDestroyLair = cf.exploreLairNeutral(caster)
	if iRnd >= 60 and iRnd < 90:
		iDestroyLair = cf.exploreLairGood(caster)
	if iRnd >= 90:
		iDestroyLair = cf.exploreLairBigGood(caster)
	if iDestroyLair > CyGame().getSorenRandNum(100, "Explore Lair"):
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LAIR_DESTROYED", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		pPlot.setImprovementType(-1)
	caster.finishMoves()
	caster.changeExperience(1, -1, false, false, false, false)

def spellExploreLairEpic(caster):
	pPlot = caster.plot()
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair") + caster.getLevel()
	iDestroyLair = 0
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	if caster.isHasPromotion(iAdventurer):
		iRnd += 10
	if iRnd < 50:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 50:
		iDestroyLair = cf.exploreLairBigGood(caster)
	if iDestroyLair > CyGame().getSorenRandNum(100, "Explore Lair"):
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LAIR_DESTROYED", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		removeEpicLair(pPlot)
	caster.finishMoves()
	caster.changeExperience(1, -1, false, false, false, false)

def removeEpicLair(pPlot):
	iLair = pPlot.getImprovementType()
	iReplace = -1
	if iLair == gc.getInfoTypeForString("IMPROVEMENT_AIFON_ISLE"):
		iReplace = gc.getInfoTypeForString("IMPROVEMENT_AIFON_ISLE_EXPLORED")
	if iLair == gc.getInfoTypeForString("IMPROVEMENT_BRADELINES_WELL"):
		iReplace = gc.getInfoTypeForString("IMPROVEMENT_BRADELINES_WELL_EXPLORED")
	if iLair == gc.getInfoTypeForString("IMPROVEMENT_BROKEN_SEPULCHER"):
		iReplace = gc.getInfoTypeForString("IMPROVEMENT_BROKEN_SEPULCHER_EXPLORED")
	if iLair == gc.getInfoTypeForString("IMPROVEMENT_PYRE_OF_THE_SERAPHIC"):
		iReplace = gc.getInfoTypeForString("IMPROVEMENT_PYRE_OF_THE_SERAPHIC_EXPLORED")
	if iLair == gc.getInfoTypeForString("IMPROVEMENT_TOWER_OF_EYES"):
		iReplace = gc.getInfoTypeForString("IMPROVEMENT_TOWER_OF_EYES_EXPLORED")
	pPlot.setImprovementType(iReplace)

def reqFeast(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getPopulation() < 3:
		return False
	return True

def spellFeast(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	caster.changeExperience(pCity.getPopulation()-2, -1, false, false, false, false)
	pCity.changeHurryAngerTimer(3)

def reqFeed(caster):
	if caster.getDamage() == 0:
		return false
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == false:
		if caster.getDamage() < 20:
			return false
	return true

def spellFeed(caster):
	caster.setDamage(caster.getDamage() - 20, caster.getOwner())
	pVictim = -1
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getOwner() == caster.getOwner():
			if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_BLOODPET'):
				if (pVictim == -1 or pVictim.getLevel() > pUnit.getLevel()):
					pVictim = pUnit
	if pVictim != -1:
		pVictim.kill(True, 0)

def reqForTheHorde(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	bPlayer = gc.getPlayer(gc.getORC_PLAYER())
	if gc.getTeam(pPlayer.getTeam()).isAtWar(bPlayer.getTeam()):
		return False
	if bPlayer.getNumUnits() == 0:
		return False
	if pPlayer.isHuman() == False:
		if bPlayer.getNumUnits() < 60:
			return False
	return True

def spellForTheHorde(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iHero = gc.getInfoTypeForString('PROMOTION_HERO')
	iOrc = gc.getInfoTypeForString('PROMOTION_ORC')
	py = PyPlayer(gc.getORC_PLAYER())
	for pUnit in py.getUnitList():
		if (pUnit.getRace() == iOrc and pUnit.isHasPromotion(iHero) == False):
			if CyGame().getSorenRandNum(100, "Bob") < 50:
				pPlot = pUnit.plot()
				for i in range(pPlot.getNumUnits(), -1, -1):
					pNewPlot = -1
					pLoopUnit = pPlot.getUnit(i)
					if pLoopUnit.isHiddenNationality():
						pNewPlot = cf.findClearPlot(pLoopUnit, -1)
						if pNewPlot != -1:
							pLoopUnit.setXY(pNewPlot.getX(), pNewPlot.getY(), false, true, true)
				newUnit = pPlayer.initUnit(pUnit.getUnitType(), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit.convert(pUnit)


def reqGiftsOfNantosuelta(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
	return True

def spellGiftsOfNantosuelta(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iGoldenHammer = gc.getInfoTypeForString('EQUIPMENT_GOLDEN_HAMMER')
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		newUnit = pPlayer.initUnit(iGoldenHammer, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def reqGiftVampirism(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			if not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
				if pUnit.getLevel() >= 6:
					return True
				if (pUnit.getLevel() >= 4 and pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MOROI')):
					return True
	return False

def spellGiftVampirism(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			if not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
				if pUnit.getLevel() >= 6:
					pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE'),True)
				if (pUnit.getLevel() >= 4 and pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MOROI')):
					pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE'),True)

def spellGiveHammerToCraftsman(caster):
	pCity = caster.plot().getPlotCity()
	pCity.changeFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_ENGINEER'), 1)

def reqHastursRazor(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getDamage() > 0:
					if pPlayer.isHuman():
						return True
					if pUnit.getOwner() == caster.getOwner():
						return True
	return False

def spellHastursRazor(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	listDamage = []
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				listDamage.append(pUnit.getDamage())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				iRnd = listDamage[CyGame().getSorenRandNum(len(listDamage), "Hasturs Razor")]
				if iRnd != pUnit.getDamage():
					CyInterface().addMessage(pUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_HASTURS_RAZOR",()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Spells/Hasturs Razor.dds',ColorTypes(7),pUnit.getX(),pUnit.getY(),True,True)
					if pUnit.getOwner() != caster.getOwner():
						CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_HASTURS_RAZOR",()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Spells/Hasturs Razor.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
					pUnit.setDamage(iRnd, caster.getOwner())

def reqHeal(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getDamage() > 0):
			return True
		if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED')):
			return True
		if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED')):
			return True
		if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BURRS')):
			return True
	return False

def spellHeal(caster,amount):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isAlive():
			pUnit.changeDamage(-amount,0) #player doesn't matter - it won't kill

def reqHealingSalve(caster):
	if caster.getDamage() == 0:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if caster.getDamage() < 25:
			return False
	return True

def spellHealingSalve(caster):
	caster.setDamage(0, caster.getOwner())
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RABIES'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), false)
	
def reqHellfire(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
		return False
	pPlot = caster.plot()
	if pPlot.isCity():
		return False
	if pPlot.isWater():
		return False
	if pPlot.getImprovementType() != -1:
		return False
	iHellFire = gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE')
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iHellFire:
				return False
	if pPlayer.isHuman() == False:
		if pPlot.isOwned():
			if pPlot.getOwner() == caster.getOwner():
				return False
	return True

def reqHeraldsCall(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			return true
	return False

def spellHeraldsCall(caster):
	iValor = gc.getInfoTypeForString('PROMOTION_VALOR')
	iBlessed = gc.getInfoTypeForString('PROMOTION_BLESSED')
	iCourage = gc.getInfoTypeForString('PROMOTION_COURAGE')
	iLoyalty = gc.getInfoTypeForString('PROMOTION_LOYALTY')
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			pUnit.setHasPromotion(iValor,True)
			pUnit.setHasPromotion(iBlessed, True)
			pUnit.setHasPromotion(iCourage, True)
			pUnit.setHasPromotion(iLoyalty, True)
			pUnit.setDuration(1)

def reqHide(caster):
	if caster.isMadeAttack():
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN')):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_INVISIBLE')):
		return False
	return True

def reqHireScorpionClan(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	bPlayer = gc.getPlayer(gc.getORC_PLAYER())
	eTeam = gc.getTeam(pPlayer.getTeam())
	if eTeam.isAtWar(bPlayer.getTeam()):
		return False
	return True

def spellHireArcher(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ARCHER_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireChariot(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_CHARIOT_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireGoblin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_GOBLIN_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireUnits(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pCity = caster.plot().getPlotCity()
	iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_MAGNADINE_HIRE_UNITS')
	triggerData = pPlayer.initTriggeredData(iEvent, true, pCity.getID(), pCity.getX(), pCity.getY(), iPlayer, -1, -1, -1, -1, -1)

def spellHireWolfRider(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WOLF_RIDER_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def reqHyboremsWhisper(caster):
	if gc.getGame().isNetworkMultiPlayer():
		return False
	pCity = cf.getAshenVeilCity(3)
	if pCity == -1:
		return False
	return True

def spellHyboremsWhisper(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_HYBOREMS_WHISPER')
	triggerData = pPlayer.initTriggeredData(iEvent, true, -1, caster.getX(), caster.getY(), iPlayer, -1, -1, -1, -1, -1)

def reqImpersonateLeader(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	if gc.getPlayer(pCity.getOwner()).isHuman():
		return False
	return True

def spellImpersonateLeader(caster):
	pCity = caster.plot().getPlotCity()
	iNewPlayer = pCity.getOwner()
	iOldPlayer = caster.getOwner()
	iTimer = 5 + CyGame().getSorenRandNum(10, "Impersonate Leader")
	CyGame().reassignPlayerAdvanced(iOldPlayer, iNewPlayer, iTimer)

def reqInquisition(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	StateBelief = pPlayer.getStateReligion()
	if StateBelief == -1:
		if caster.getOwner() != pCity.getOwner():
			return False
	if (StateBelief != gc.getPlayer(pCity.getOwner()).getStateReligion()):
		return False
	for iTarget in range(gc.getNumReligionInfos()):
		if (StateBelief != iTarget and pCity.isHasReligion(iTarget) and pCity.isHolyCityByType(iTarget) == False):
			return True
	return False

def spellInquisition(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	StateBelief = gc.getPlayer(pCity.getOwner()).getStateReligion()
	iRnd = CyGame().getSorenRandNum(4, "Bob")
	if StateBelief == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
		iRnd = iRnd - 1
	for iTarget in range(gc.getNumReligionInfos()):
		if (not StateBelief == iTarget and pCity.isHasReligion(iTarget) and not pCity.isHolyCityByType(iTarget)):
			pCity.setHasReligion(iTarget, False, True, True)
			iRnd = iRnd + 1
			for i in range(gc.getNumBuildingInfos()):
				if gc.getBuildingInfo(i).getPrereqReligion() == iTarget:
					pCity.setNumRealBuilding(i, 0)
	if iRnd >= 1:
		pCity.changeHurryAngerTimer(iRnd)
# Scions start - Allows Inqusition to remove Scions Sympathizers, Poisioned Words, Corrupt Guild.	
	pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_SCIONS_SYMPATHISERS'), 0)
# Scions end

def reqIntoTheMist(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getNumUnits() < 40:
			return False
	return True

def spellIntoTheMist(caster):
	iInvisible = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		pUnit.setHasPromotion(iInvisible, True)

def reqIraUnleashed(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_IRA')) >= 4:
		return False
	return True

def spellIraUnleashed(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iCount = 4 - pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_IRA'))
	for i in range(iCount):
		pPlayer.initUnit(gc.getInfoTypeForString('UNIT_IRA'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def reqKidnap(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getTeam() == caster.getTeam():
		return False
	i = 0
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST'))
	if i == 0:
		return False
	return True

def spellKidnap(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_PROPHET')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_ARTIST')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_MERCHANT')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_ENGINEER')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_SCIENTIST')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST')
	iChance = caster.baseCombatStr() * 8
	if iChance > 95:
		iChance = 95
	pPlayer = gc.getPlayer(caster.getOwner())
	if CyGame().getSorenRandNum(100, "Kidnap") <= iChance:
		newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		pCity.changeFreeSpecialistCount(iSpec, -1)
	else:
		if CyGame().getSorenRandNum(100, "Kidnap") <= 50:
			caster.setXY(pPlayer.getCapitalCity().getX(), pPlayer.getCapitalCity().getY(), false, true, true)
		else:
			caster.kill(True, 0)
		cf.startWar(caster.getOwner(), pCity.getOwner(), WarPlanTypes.WARPLAN_TOTAL)

def reqLegends(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
	return True

def spellLegends(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		pCity.changeCulture(iPlayer, 300, True)

def reqLichdom(caster):
	if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_FLESH_GOLEM'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PUPPET')):
		return False
	if isWorldUnitClass(caster.getUnitClassType()):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_LICH')) >= 4:
		return False
	return True

def reqMask(caster):
	if caster.isHiddenNationality():
		return False
	if caster.hasCargo():
		return False
	if caster.isCargo():
		return False
	pGroup = caster.getGroup()
	if pGroup.isNone() == False:
		if pGroup.getNumUnits() > 1:
			return False
	return True

def reqMezmerizeAnimal(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iAnimal = gc.getPlayer(gc.getANIMAL_PLAYER())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
					if pUnit.getTeam() == iAnimal.getTeam():
						return True
					if eTeam.isAtWar(pUnit.getTeam()):
						return True
	return False

def spellMezmerizeAnimal(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iAnimal = gc.getPlayer(gc.getANIMAL_PLAYER())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.isDelayedDeath() == False:
							if pUnit.isResisted(caster, gc.getInfoTypeForString('SPELL_MEZMERIZE_ANIMAL')) == False:
								newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.convert(pUnit)
					if pUnit.getTeam() == iAnimal.getTeam():
						if pUnit.isDelayedDeath() == False:
							if pUnit.isResisted(caster, gc.getInfoTypeForString('SPELL_MEZMERIZE_ANIMAL')) == False:
								newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.convert(pUnit)

def reqMirror(caster):
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	if caster.isImmuneToMagic():
		return False
	if pPlot.isVisibleEnemyUnit(iPlayer):
		return False
	return True

def spellMirror(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	newUnit = pPlayer.initUnit(caster.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	for i in range(gc.getNumPromotionInfos()):
		newUnit.setHasPromotion(i, caster.isHasPromotion(i))
		if gc.getPromotionInfo(i).isEquipment():
			newUnit.setHasPromotion(i, False)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION'), True)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), False)
	if newUnit.isImmortal():
		newUnit.changeImmortal(-1)
	newUnit.setDamage(caster.getDamage(), caster.getOwner())
	newUnit.setLevel(caster.getLevel())
	newUnit.setExperience(caster.getExperience(), -1)
	newUnit.setHasCasted(True)
	newUnit.setDuration(1)

def reqPeace(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_CHANGING_WAR_PEACE):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	if eTeam.getAtWarCount(True) == 0:
		return False
	return True

def spellPeace(caster):
	eTeam = gc.getTeam(gc.getPlayer(caster.getOwner()).getTeam())
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if (pPlayer.isAlive() and iPlayer != caster.getOwner() and not gc.getPlayer(iPlayer).isBarbarian()):
			i2Team = gc.getPlayer(iPlayer).getTeam()
			if eTeam.isAtWar(i2Team):
				eTeam.makePeace(i2Team)
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.changeGlobalCounterContrib(-1 * (CyGame().getGlobalCounter() / 2))

def reqPeaceSevenPines(caster):
	pPlot = caster.plot()
	if not pPlot.isPythonActive():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	if eTeam.getAtWarCount(True) == 0:
		return False
	return True

def spellPeaceSevenPines(caster):
	eTeam = gc.getTeam(gc.getPlayer(caster.getOwner()).getTeam())
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if (pPlayer.isAlive() and iPlayer != caster.getOwner() and not gc.getPlayer(iPlayer).isBarbarian()):
			i2Team = gc.getPlayer(iPlayer).getTeam()
			if eTeam.isAtWar(i2Team):
				eTeam.makePeace(i2Team)
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.changeGlobalCounterContrib(-1 * (CyGame().getGlobalCounter() / 2))
	pPlot = caster.plot()
	pPlot.setPythonActive(False)

def reqPillarofFire(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			bEnemy = false
			bNeutral = false
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					bEnemy = true
				else:
					bNeutral = true
			if (bEnemy and bNeutral == false):
				return true
	return false

def spellPillarofFire(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iBestValue = 0
	pBestPlot = -1
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			bNeutral = false
			iValue = 0
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					iValue += 5 * pUnit.baseCombatStr()
				else:
					bNeutral = true
			if (iValue > iBestValue and bNeutral == false):
				iBestValue = iValue
				pBestPlot = pPlot
	if pBestPlot != -1:
		for i in range(pBestPlot.getNumUnits()):
			pUnit = pBestPlot.getUnit(i)
			pUnit.doDamage(50, 75, caster, gc.getInfoTypeForString('DAMAGE_FIRE'), true)
		if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE')):
			bValid = True
			iImprovement = pPlot.getImprovementType()
			if iImprovement != -1 :
				if gc.getImprovementInfo(iImprovement).isPermanent():
					bValid = False
			if bValid:
				if CyGame().getSorenRandNum(100, "Flames Spread") <= gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
					pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE'),pBestPlot.getPoint())

def reqMarchOfTheTrees(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellMarchOfTheTrees(caster):
	iAncientForest = gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iNewForest = gc.getInfoTypeForString('FEATURE_FOREST_NEW')
	iTreant = gc.getInfoTypeForString('UNIT_TREANT')
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				if (pPlot.getFeatureType() == iForest or pPlot.getFeatureType() == iAncientForest):
					if not pPlot.isVisibleEnemyUnit(iPlayer):
						newUnit = pPlayer.initUnit(iTreant, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setDuration(5)
						pPlot.setFeatureType(iNewForest,0)

def reqMotherLode(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if ((pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_QUARRY'))) + (pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_MINE')))) < 10:
			return False
	return True

def spellMotherLode(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer.changeGold(pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_MINE')) * 35)
	pPlayer.changeGold(pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_QUARRY')) * 20)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				if pPlot.isWater() == False:
					if pPlot.isPeak() == False:
						if pPlot.isHills() == False:
							if CyGame().getSorenRandNum(100, "Mother Lode") < 10:
								pPlot.setPlotType(PlotTypes.PLOT_HILLS, True, True)

def reqOpenChest(caster):
	iTreasure = gc.getInfoTypeForString('EQUIPMENT_TREASURE')
	pPlot = caster.plot()
	pTreasure = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iTreasure:
			if pUnit.getOwner() == caster.getOwner():
				pTreasure = pUnit
	if pTreasure == -1:
		return False
	return True

def spellOpenChest(caster):
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	bValid = True
	if CyGame().getWBMapScript():
		bValid = sf.openChest(caster, pPlot)
	if bValid:
		if CyGame().getSorenRandNum(100, "Explore Lair") < 25:
			lTrapList = ['POISON', 'FIRE', 'SPORES']
			sTrap = lTrapList[CyGame().getSorenRandNum(len(lTrapList), "Pick Trap")-1]
			point = pPlot.getPoint()
			if sTrap == 'POISON':
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), True)
				caster.doDamageNoCaster(25, 90, gc.getInfoTypeForString('DAMAGE_POISON'), false)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_POISON", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/Poisoned.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			if sTrap == 'FIRE':
				caster.doDamageNoCaster(50, 90, gc.getInfoTypeForString('DAMAGE_FIRE'), false)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_FIRE", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Ring of Flames.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_RING_OF_FLAMES'),point)
				CyAudioGame().Play3DSound("AS3D_SPELL_FIREBALL",point.x,point.y,point.z)
			if sTrap == 'SPORES':
				caster.changeImmobileTimer(3)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_SPORES", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Spores.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPORES'),point)
				CyAudioGame().Play3DSound("AS3D_SPELL_CONTAGION",point.x,point.y,point.z)

		lList = ['EMPTY', 'HIGH_GOLD', 'ITEM_HEALING_SALVE', 'ITEM_JADE_TORC', 'ITEM_ROD_OF_WINDS', 'ITEM_TIMOR_MASK', 'TECH', 'HEART_AMULET', 'SWIFT_BOOTS', 'TRAVELLERS_CLOAK', 'RING_OF_PERCEPTION', 'RING_OF_STRIKING', 'COMPELLING_JEWEL', 'TOKEN_OF_RAGNAROK', 'MENACING_HELM', 'HAUBERK_OF_ABJURATION', 'HOLY_HAND_GRENADE']
		sGoody = lList[CyGame().getSorenRandNum(len(lList), "Pick Goody")-1]
		if sGoody == 'EMPTY':
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_EXPLORE_LAIR_TREASURE_EMPTY",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Equipment/Treasure.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if sGoody == 'HIGH_GOLD':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_HIGH_GOLD'), caster)
		if sGoody == 'ITEM_HEALING_SALVE':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_HEALING_SALVE'), caster)
		if sGoody == 'ITEM_JADE_TORC':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_JADE_TORC'), caster)
		if sGoody == 'ITEM_POTION_OF_INVISIBILITY':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_POTION_OF_INVISIBILITY'), caster)
		if sGoody == 'ITEM_POTION_OF_RESTORATION':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_POTION_OF_RESTORATION'), caster)
		if sGoody == 'ITEM_ROD_OF_WINDS':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_ROD_OF_WINDS'), caster)
		if sGoody == 'ITEM_TIMOR_MASK':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_TIMOR_MASK'), caster)
		if sGoody == 'TECH':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster)
		if sGoody == 'HEART_AMULET':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEART_AMULET'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'SWIFT_BOOTS':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SWIFT_BOOTS'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'TRAVELLERS_CLOAK':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_TRAVELLERS_CLOAK'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'RING_OF_PERCEPTION':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RING_OF_PERCEPTION'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'RING_OF_STRIKING':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RING_OF_STRIKING'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'HOLY_HAND_GRENADE':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HOLY_HAND_GRENADE'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'COMPELLING_JEWEL':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMPELLING_JEWEL'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'TOKEN_OF_RAGNAROK':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CURSED_TOKEN_OF_RAGNAROK'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		if sGoody == 'MENACING_HELM':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MENACING_HELM'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100	
		if sGoody == 'HAUBERK_OF_ABJURATION':
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HAUBERK_OF_ABJURATION'), True)
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARTIFACT",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/FlamingArrows.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			return 100
		pTreasure = -1
		iTreasure = gc.getInfoTypeForString('EQUIPMENT_TREASURE')
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getUnitType() == iTreasure:
				pTreasure = pUnit
		pTreasure.kill(True, 0)

def reqPromoteSettlement(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if not pCity.isSettlement():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() - pPlayer.getNumSettlements() >= pPlayer.getMaxCities():
		return False
	return True

def spellPromoteSettlement(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setSettlement(False)
	pCity.setPlotRadius(3)

def reqRagingSeas(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		eTeam = gc.getTeam(pPlayer.getTeam())
		iArcane = gc.getInfoTypeForString('UNITCLASS_ARCANE_BARGE')
		iCaravel = gc.getInfoTypeForString('UNITCLASS_CARAVEL')
		iGalley = gc.getInfoTypeForString('UNITCLASS_GALLEY')
		iFrigate = gc.getInfoTypeForString('UNITCLASS_FRIGATE')
		iGalleon = gc.getInfoTypeForString('UNITCLASS_GALLEON')
		iManOWar = gc.getInfoTypeForString('UNITCLASS_MAN_O_WAR')
		iPrivateer = gc.getInfoTypeForString('UNITCLASS_PRIVATEER')
		iQueenOfTheLine = gc.getInfoTypeForString('UNITCLASS_QUEEN_OF_THE_LINE')
		iTrireme = gc.getInfoTypeForString('UNITCLASS_TRIREME')
		for iPlayer2 in range(gc.getMAX_PLAYERS()):
			pPlayer2 = gc.getPlayer(iPlayer2)
			if pPlayer2.isAlive():
				iTeam2 = gc.getPlayer(iPlayer2).getTeam()
				if eTeam.isAtWar(iTeam2):
					iCount = pPlayer2.getUnitClassCount(iArcane)
					iCount += pPlayer2.getUnitClassCount(iCaravel)
					iCount += pPlayer2.getUnitClassCount(iGalley)
					iCount += pPlayer2.getUnitClassCount(iFrigate) * 2
					iCount += pPlayer2.getUnitClassCount(iGalleon) * 2
					iCount += pPlayer2.getUnitClassCount(iManOWar) * 3
					iCount += pPlayer2.getUnitClassCount(iPrivateer)
					iCount += pPlayer2.getUnitClassCount(iQueenOfTheLine) * 3
					iCount += pPlayer2.getUnitClassCount(iTrireme)
					if iCount > 10:
						return True
		return False
	return True

def spellRagingSeas(caster):
	iCold = gc.getInfoTypeForString('DAMAGE_COLD')
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iLanun = gc.getInfoTypeForString('CIVILIZATION_LANUN')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSpring = gc.getInfoTypeForString('EFFECT_SPRING')
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isAdjacentToWater():
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getCivilizationType() != iLanun:
					pUnit.doDamageNoCaster(75, 100, iCold, false)
			if pPlot.getImprovementType() != -1:
				if pPlot.getFeatureType() == iFlames:
					pPlot.setFeatureType(-1, 0)
				if pPlot.getImprovementType() == iSmoke:
					pPlot.setImprovementType(-1)
				else:
					if pPlot.isOwned():
						if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
							if gc.getPlayer(pPlot.getOwner()).getCivilizationType() != iLanun:
								if CyGame().getSorenRandNum(100, "Raging Seas") <= 25:
									pPlot.setImprovementType(-1)
			if pPlot.isVisibleToWatchingHuman():
				CyEngine().triggerEffect(iSpring,pPlot.getPoint())

def spellRaiseSkeleton(caster):
	pPlot = caster.plot()
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD'):
		pPlot.setImprovementType(-1)
		caster.cast(gc.getInfoTypeForString('SPELL_RAISE_SKELETON'))
		caster.cast(gc.getInfoTypeForString('SPELL_RAISE_SKELETON'))

def reqRally(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_CULTURAL_VALUES')) != gc.getInfoTypeForString('CIVIC_CRUSADE'):
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
	return True

def spellRally(caster):
	iOwner = caster.getOwner()
	pPlayer = gc.getPlayer(iOwner)
	iDemagog = gc.getInfoTypeForString('UNIT_DEMAGOG')
	iTown = gc.getInfoTypeForString('IMPROVEMENT_TOWN')
	iVillage = gc.getInfoTypeForString('IMPROVEMENT_VILLAGE')
	iCount = 0
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.getOwner() == iOwner:
			if pPlot.isCity():
				newUnit = pPlayer.initUnit(iDemagog, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			if pPlot.getImprovementType() == iTown:
				pPlot.setImprovementType(iVillage)
				newUnit = pPlayer.initUnit(iDemagog, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellReadTheGrimoire(caster):
	iRnd = CyGame().getSorenRandNum(100, "Read the Grimoire")
	if iRnd < 20:
		caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_SPECTRE'))
	if iRnd >= 20 and iRnd < 40:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), True)
	if iRnd >= 40 and iRnd < 60:
		caster.cast(gc.getInfoTypeForString('SPELL_WITHER'))
	if iRnd >= 60 and iRnd < 70:
		caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_PIT_BEAST'))
	if iRnd >= 70 and iRnd < 80:
		caster.cast(gc.getInfoTypeForString('SPELL_BURNING_BLOOD'))
	if iRnd >= 80 and iRnd < 90:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), True)
	if iRnd >= 90:
		caster.kill(True, PlayerTypes.NO_PLAYER)

def reqRebuildBarnaxus(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCityPlayer = gc.getPlayer(pCity.getOwner())
	if caster.getUnitType() == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		return False
	if pCityPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		return False
	return True

def spellRebuildBarnaxus(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pCityPlayer = gc.getPlayer(pCity.getOwner())
	newUnit = pCityPlayer.initUnit(gc.getInfoTypeForString('UNIT_BARNAXUS'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	newUnit.setDamage(75, caster.getOwner())
	newUnit.finishMoves()
	pCity.applyBuildEffects(newUnit)
	if pPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		pCityPlayer.AI_changeAttitudeExtra(iPlayer,2)

def spellRecruit(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = gc.getTeam(pPlayer.getTeam())
	iLoop = (pCity.getPopulation() / 3) + 1
	if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_TEMPLE_OF_THE_ORDER')) == 1:
		iLoop = iLoop * 2
	for i in range(iLoop):
		iRnd = CyGame().getSorenRandNum(60, "Bob")
		iUnit = -1
		if iRnd <= 10:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HANDLING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_RANGER')
		elif iRnd <= 20:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_POISONS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_ASSASSIN')
		elif iRnd <= 30:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_STIRRUPS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSE_ARCHER')
		elif iRnd <= 40:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_TRADE')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_CHARIOT')
		elif iRnd <= 50:
			iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BRONZE_WORKING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_AXEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_IRON_WORKING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_CHAMPION')
		elif iRnd <= 60:
			iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_ARCHER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BOWYERS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_LONGBOWMAN')
		if iUnit != -1:
			infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
			iUnit = infoCiv.getCivilizationUnits(iUnit)
			if iUnit != -1:
				newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RECRUITER'), False)
	if caster.getUnitType() != gc.getInfoTypeForString('UNIT_DONAL'):
		caster.kill(True, PlayerTypes.NO_PLAYER)

def reqRecruitMercenary(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		pPlot = caster.plot()
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KHAZAD'):
			return False
		iX = caster.getX()
		iY = caster.getY()
		eTeam = gc.getTeam(pPlayer.getTeam())
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					p2Player = gc.getPlayer(pUnit.getOwner())
					e2Team = p2Player.getTeam()
					if eTeam.isAtWar(e2Team) == True:
						return True
		return False
	return True

def spellRecruitMercenary(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNITCLASS_MERCENARY')
	infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
	iUnit = infoCiv.getCivilizationUnits(iUnit)
	newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	newUnit.finishMoves()
	newUnit.setHasCasted(True)
	if caster.getUnitType() == gc.getInfoTypeForString('UNIT_MAGNADINE'):
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)

#### EXPANDED MERCENARIES - westamastaflash - 08/03/2008 ####

def spellRecruitMercenary_em(caster):	
	mercenaryList = []
	mercenaryListObj = RandomMercenaryList.randomMercenaryList(caster)
	mercenaryList = mercenaryListObj.getMercenaryList()	
	CvScreensInterface.showMercenaryChooserScreen([caster, mercenaryList[:]])

def reqSpreadGuildOfTheNine(caster):
	iGuildOfTheNine = gc.getInfoTypeForString('CORPORATION_GUILD_OF_THE_NINE')
	if not CyGame().isCorporationFounded(iGuildOfTheNine):
		return false
	if caster.plot().getPlotCity().isHasCorporation(iGuildOfTheNine):
		return false
	return true

def spreadGuildOfTheNine(caster):
	iGuildOfTheNine = gc.getInfoTypeForString('CORPORATION_GUILD_OF_THE_NINE')
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()	
	pCity.setHasCorporation(iGuildOfTheNine, True, False, False)

def reqFoundGuildOfTheNine(caster):
	iGuildOfTheNine = gc.getInfoTypeForString('CORPORATION_GUILD_OF_THE_NINE')
	if CyGame().isCorporationFounded(iGuildOfTheNine):
		return false
	return true

def effectMercenaryPromotion(caster):
	return
#### END EXPANDED MERCENARIES SECTION ####

def reqReleaseFromCage(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD')):
		return False
	return True

def spellReleaseFromCage(caster):
	pPlot = caster.plot()
	pPlot.setImprovementType(-1)

def reqReligiousFervor(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iReligion = pPlayer.getStateReligion()
	if iReligion == -1:
		return False
	if pPlayer.isHuman() == False:
		iCount = 0
		for pyCity in PyPlayer(iPlayer).getCityList() :
			pCity = pyCity.GetCy()
			if pCity.isHasReligion(iReligion):
				iCount += 1
		if iCount < 5:
			return False
	return True

def spellReligiousFervor(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iReligion = pPlayer.getStateReligion()
	if iReligion == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES')
	if iReligion == gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_KILMORPH')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_EMPYREAN')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_ORDER')
	if iReligion == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_OVERLORDS')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_VEIL')
	if iReligion == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
		iUnit = gc.getInfoTypeForString('UNIT_ASSASSIN')
	iCount = 0
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		if pCity.isHasReligion(iReligion):
			iCount += 1
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		newUnit = pPlayer.initUnit(iUnit, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.changeExperience(iCount, -1, False, False, False, False)
		newUnit.setReligion(iReligion)

def reqRepair(caster):
	pPlot = caster.plot()
	iGolem = gc.getInfoTypeForString('PROMOTION_GOLEM')
	iNaval = gc.getInfoTypeForString('UNITCOMBAT_NAVAL')
	iSiege = gc.getInfoTypeForString('UNITCOMBAT_SIEGE')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getUnitCombatType() == iSiege or pUnit.getUnitCombatType() == iNaval or pUnit.isHasPromotion(iGolem)):
			if pUnit.getDamage() > 0:
				return True
	return False

def spellRepair(caster,amount):
	pPlot = caster.plot()
	iGolem = gc.getInfoTypeForString('PROMOTION_GOLEM')
	iNaval = gc.getInfoTypeForString('UNITCOMBAT_NAVAL')
	iSiege = gc.getInfoTypeForString('UNITCOMBAT_SIEGE')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getUnitCombatType() == iSiege or pUnit.getUnitCombatType() == iNaval or pUnit.isHasPromotion(iGolem)):
			pUnit.changeDamage(-amount,0)

def reqRessurection(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iHero = cf.getHero(pPlayer)
	if iHero == -1:
		return False
	if not CyGame().isUnitClassMaxedOut(iHero, 0):
		return False
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.getUnitClassCount(iHero) > 0:
			return False
	py = PyPlayer(caster.getOwner())
	iSpell = gc.getInfoTypeForString('SPELL_RESSURECTION')
	for pUnit in py.getUnitList():
		if pUnit.getDelayedSpell() == iSpell:
			return False
# Scions start - Hopefully prevents innapropriate Korrina ressurections.
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_KORRINA_BLACK')) > 0:
		return False
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_KORRINA_RED')) > 0:
		return False
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_KORRINA')) > 0:
		return False
# Scions end	
	return True

def spellRessurection(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iHero = cf.getHero(pPlayer)
	infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
	iUnit = infoCiv.getCivilizationUnits(iHero)
	iBarn = gc.getInfoTypeForString('EQUIPMENT_PIECES_OF_BARNAXUS')
	iBarnProm = gc.getInfoTypeForString('PROMOTION_PIECES_OF_BARNAXUS')
	if iUnit == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		for iPlayer2 in range(gc.getMAX_PLAYERS()):
			pPlayer2 = gc.getPlayer(iPlayer2)
			if pPlayer2.isAlive():
				py = PyPlayer(iPlayer2)
				for pUnit in py.getUnitList():
					if pUnit.isHasPromotion(iBarnProm):
						pUnit.setHasPromotion(iBarnProm, False)
						CyInterface().addMessage(iPlayer2,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_PIECES_LOST", ()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Units/Barnaxus.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
					if pUnit.getUnitType() == iBarn:
						CyInterface().addMessage(iPlayer2,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_PIECES_LOST", ()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Units/Barnaxus.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
						pUnit.kill(True, PlayerTypes.NO_PLAYER)
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	for iProm in range(gc.getNumPromotionInfos()):
		if newUnit.isHasPromotion(iProm):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
	CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_HERO_RESSURECTED", ()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Spells/Ressurection.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)

def spellRessurectionGraveyard(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
	iUnit = infoCiv.getCivilizationUnits(gc.getInfoTypeForString('UNITCLASS_CHAMPION'))
	if iUnit == -1:
		iUnit = gc.getInfoTypeForString('UNIT_CHAMPION')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.changeExperience(CyGame().getSorenRandNum(30, "Ressurection Graveyard"), -1, False, False, False, False)
	pPlot.setImprovementType(-1)

def reqRevelry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isGoldenAge():
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getTotalPopulation() < 25:
			return False
	return True

def spellRevelry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.changeGoldenAgeTurns(CyGame().goldenAgeLength() * 2)

def reqRevelation(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	iX = caster.getX()
	iY = caster.getY()
	iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
	iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')
	for iiX in range(iX-3, iX+4, 1):
		for iiY in range(iY-3, iY+4, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for iUnit in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(iUnit)
				if pUnit.getTeam() != iTeam:
					if pUnit.isHasPromotion(iHidden):
						return True
					if pUnit.isHasPromotion(iHiddenNationality):
						return True
					if pUnit.isHasPromotion(iInvisible):
						return True
					if pUnit.isHasPromotion(iIllusion):
						return True
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WHITEOUT')):
						return True
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_OF_ESUS')):
						return True
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FOREST_STEALTH')):
						return True
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HAUNTSTALK')):
						return True
	return False

def spellRevelation(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	iX = caster.getX()
	iY = caster.getY()
	iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
	iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')
	for iiX in range(iX-3, iX+4, 1):
		for iiY in range(iY-3, iY+4, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for iUnit in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(iUnit)
				if pUnit.getTeam() != iTeam:
					if pUnit.isHasPromotion(iHidden):
						pUnit.setHasPromotion(iHidden, False)
					if pUnit.isHasPromotion(iHiddenNationality):
						pUnit.setHasPromotion(iHiddenNationality, False)
					if pUnit.isHasPromotion(iInvisible):
						pUnit.setHasPromotion(iInvisible, False)
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WHITEOUT')):
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WHITEOUT'), False)
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_OF_ESUS')):
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_OF_ESUS'), False)
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FOREST_STEALTH')):
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FOREST_STEALTH'), False)
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HAUNTSTALK')):
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HAUNTSTALK'), False)
					if pUnit.isHasPromotion(iIllusion):
						pUnit.kill(True, caster.getOwner())

def spellRingofFlames(caster):
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			if not (iiX == iX and iiY == iY):
				pPlot = CyMap().plot(iiX,iiY)
				bValid = True
				if pPlot.getImprovementType() != -1:
					if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent():
						bValid = False
				if bValid:
					if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
						if CyGame().getSorenRandNum(100, "Flames Spread") <= gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
							pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))

def reqRiverOfBlood(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
	return True

def spellRiverOfBlood(caster):
	iOwner = caster.getOwner()
	iScions = gc.getInfoTypeForString('CIVILIZATION_SCIONS')
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.isAlive():
			if iPlayer != iOwner:
				for pyCity in PyPlayer(iPlayer).getCityList() :
					pCity = pyCity.GetCy()
					if pCity.getPopulation() > 2:
						pCity.changePopulation(-2)
						CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_RIVER_OF_BLOOD", ()),'',1,'Art/Interface/Buttons/Spells/River of Blood.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
						if gc.getPlayer(pCity.getOwner()).getCivilizationType() == iScions:
							pCity.changePopulation(1)
			if iPlayer == iOwner:
				for pyCity in PyPlayer(iPlayer).getCityList() :
					pCity = pyCity.GetCy()
					pCity.changePopulation(2)

def reqRoar(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = gc.getTeam(pPlayer.getTeam())
	iX = caster.getX()
	iY = caster.getY()
	iTarget = -1
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if not pUnit.isImmuneToFear():
					p2Player = gc.getPlayer(pUnit.getOwner())
					e2Team = p2Player.getTeam()
					if eTeam.isAtWar(e2Team) == True:
						return True
	return False

def spellRoar(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	eTeam = gc.getTeam(pPlayer.getTeam())
	pPlot = caster.plot()
	iX = caster.getX()
	iY = caster.getY()
	iDragon = gc.getInfoTypeForString('PROMOTION_CULT_OF_THE_DRAGON')
	iLoyalty = gc.getInfoTypeForString('PROMOTION_LOYALTY')
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if not pLoopPlot.isNone():
				for i in range(pLoopPlot.getNumUnits() -1, -1, -1):
					pUnit = pLoopPlot.getUnit(i)
					p2Player = gc.getPlayer(pUnit.getOwner())
					i2Team = p2Player.getTeam()
					if eTeam.isAtWar(i2Team):
						if cf.doFear(pUnit, pPlot, caster, True):
							CyInterface().addMessage(pUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR", (gc.getUnitInfo(pUnit.getUnitType()).getDescription(), )),'',1,'Art/Interface/Buttons/Spells/Roar.dds',ColorTypes(7),pUnit.getX(),pUnit.getY(),True,True)
							CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR_ENEMY", (gc.getUnitInfo(pUnit.getUnitType()).getDescription(), )),'',1,'Art/Interface/Buttons/Spells/Roar.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
					if (pUnit.getTeam() != caster.getTeam() and pUnit.isHasPromotion(iDragon)):
						if pUnit.isHasPromotion(iLoyalty):
							pUnit.kill(True, 0)
						else:
							newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							newUnit.convert(pUnit)

def reqRobGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_GOOD'):
			return False
	return True

def spellRobGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.changeGlobalCounterContrib(1)
	pPlot = caster.plot()
	pPlot.setImprovementType(-1)
	lList = ['LOW_GOLD', 'HIGH_GOLD', 'SPAWN_SKELETONS', 'SPAWN_SPECTRE']
	if pPlayer.canReceiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster):
		lList = lList + ['TECH']
	sGoody = lList[CyGame().getSorenRandNum(len(lList), "Pick Goody")-1]
	if sGoody == 'LOW_GOLD':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_LOW_GOLD'), caster)
	if sGoody == 'HIGH_GOLD':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_HIGH_GOLD'), caster)
	if sGoody == 'TECH':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster)
	if sGoody == 'SPAWN_SKELETONS':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_SKELETONS'), caster)
	if sGoody == 'SPAWN_SPECTRE':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_SPECTRE'), caster)

def spellSacrificeAltar(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iTech = pPlayer.getCurrentResearch()
	iNum = 10 + (caster.getLevel() * caster.getLevel())
	eTeam.changeResearchProgress(iTech, iNum, caster.getOwner())

def spellSacrificePyre(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	caster.cast(gc.getInfoTypeForString('SPELL_RING_OF_FLAMES'))
	if caster.isImmortal():
		caster.changeImmortal(-1)
	iCount = 1
	if isWorldUnitClass(caster.getUnitClassType()):
		iCount = 7
	for i in range(iCount):
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIRE_ELEMENTAL'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def reqSanctify(caster):
	pPlot = caster.plot()
	bValid = False
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FALLOUT'):
		bValid = True
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'):
		return True
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_CITY_RUINS'):
		return True
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_HAUNTED_RUINS'):
		return True
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD'):
		return True
	iX = pPlot.getX()
	iY = pPlot.getY()
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		iBrokenLands = gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS')
		iBurningSands = gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')
		iFieldsOfPerdition = gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')
		iShallows = gc.getInfoTypeForString('TERRAIN_SHALLOWS')
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					iTerrain = pPlot.getTerrainType()
					if (iTerrain == iBrokenLands or iTerrain == iBurningSands or iTerrain == iFieldsOfPerdition or iTerrain == iShallows):
						bValid = True
	else:
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					if pPlot.getPlotCounter() > 0:
						bValid = True
	if bValid == False:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		if caster.getOwner() != pPlot.getOwner():
			return False
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
			return False
	return True

def spellSanctify(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FALLOUT'):
		pPlot.setFeatureType(-1, -1)
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'):
		pPlot.setFeatureType(-1, -1)
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_CITY_RUINS'):
		pPlot.setImprovementType(-1)
		pPlayer.changeGlobalCounterContrib(-1)
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_HAUNTED_RUINS'):
		pPlot.setImprovementType(-1)
		pPlayer.changeGlobalCounterContrib(-1)
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD'):
		pPlot.setImprovementType(-1)
		pPlayer.changeGlobalCounterContrib(-1)
		pPlayer = gc.getPlayer(caster.getOwner())
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_EINHERJAR'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	iX = pPlot.getX()
	iY = pPlot.getY()
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		iBrokenLands = gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS')
		iBurningSands = gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')
		iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
		iFieldsOfPerdition = gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')
		iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
		iMarsh = gc.getInfoTypeForString('TERRAIN_MARSH')
		iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
		iShallows = gc.getInfoTypeForString('TERRAIN_SHALLOWS')
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					iTerrain = pPlot.getTerrainType()
# FlavourMod: Changed by Jean Elcard 03/30/2009 (FastRebuild)
					'''
					if iTerrain == iBrokenLands:
						pPlot.setTerrainType(iGrass, True, True)
					if iTerrain == iBurningSands:
						pPlot.setTerrainType(iDesert, True, True)
					if iTerrain == iFieldsOfPerdition:
						pPlot.setTerrainType(iPlains, True, True)
					if iTerrain == iShallows:
						pPlot.setTerrainType(iMarsh, True, True)
					'''
					if iTerrain == iBrokenLands:
						pPlot.setTerrainType(iGrass, False, False)
					if iTerrain == iBurningSands:
						pPlot.setTerrainType(iDesert, False, False)
					if iTerrain == iFieldsOfPerdition:
						pPlot.setTerrainType(iPlains, False, False)
					if iTerrain == iShallows:
						pPlot.setTerrainType(iMarsh, False, False)
# FlavourMod: End Change
	else:
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if pPlot.getPlotCounter() > 0:
					pPlot.changePlotCounter(pPlot.getPlotCounter() * -1)
# FlavourMod: Added by Jean Elcard 03/30/2009 (FastRebuild)
		cf.rebuildGraphics()
# FlavourMod: End Add

def reqSanctuary(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if not pPlayer.isHuman():
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellSanctuary(caster):
	iPlayer = caster.getOwner()
	iTeam = caster.getTeam()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer.changeSanctuaryTimer(30)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				for i in range(pPlot.getNumUnits(), -1, -1):
					pUnit = pPlot.getUnit(i)
					if pUnit.getTeam() != iTeam:
						pUnit.jumpToNearestValidPlot()

def reqSandLion(caster):
	pPlot = caster.plot()
	if (pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_DESERT') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')):
		return False
	return True

# FlavourMod: Changed by Jean Elcard 03/14/2009
'''
def reqScorch(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS') or pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO'):
				return False
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
				return False
		return True	
	return False

def spellScorch(caster):
	pPlot = caster.plot()
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	if pPlot.isOwned():
		cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
'''

def reqScorch(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	sValidTerrains = ['SNOW', 'TUNDRA', 'GRASS', 'PLAINS', 'FIELDS_OF_PERDITION']
	iValidTerrains = [gc.getInfoTypeForString('TERRAIN_' + sTerrain) for sTerrain in sValidTerrains]
	if (pPlot.getTerrainType() in iValidTerrains):
		if not pPlayer.isHuman():
			if gc.getInfoTypeForString('TERRAIN_SNOW'):
				if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
					return False
				elif caster.getOwner() != pPlot.getOwner():
					return False
			elif caster.getOwner() == pPlot.getOwner():
				return False
		return True
	return False

def spellScorch(caster):
	pPlot = caster.plot()
	iTerrain = pPlot.getTerrainType()
	iFeature = pPlot.getFeatureType()
	iImprovement = pPlot.getImprovementType()
	sFlammableFeatures = ['FOREST', 'FOREST_NEW', 'FOREST_ANCIENT', 'JUNGLE', 'DEEP_JUNGLE', 'SCRUB']
	iFlammableFeatures = [gc.getInfoTypeForString('FEATURE_' + sFeature) for sFeature in sFlammableFeatures]
	sForestFeatures = ['FEATURE_FOREST', 'FEATURE_FOREST_NEW']
	iForestFeatures = [gc.getInfoTypeForString(sFeature) for sFeature in sForestFeatures]
	# spawn a defender in scorched terrain
	if iFeature == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT'):
		pSpawnPlot = cf.findClearPlot(UnitTypes.NO_UNIT, pPlot)
		if pSpawnPlot != -1:
			iTreant = gc.getInfoTypeForString('UNIT_TREANT')
			eDirection = directionXYFromPlot(pSpawnPlot, pPlot)
			pBarbarianPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
			pTreant = pBarbarianPlayer.initUnit(iTreant, pSpawnPlot.getX(), pSpawnPlot.getY(), UnitAITypes.NO_UNITAI, eDirection)
			pTreant.setDuration(5)
	if iFeature == gc.getInfoTypeForString('FEATURE_JUNGLE'):
		if CyGame().getSorenRandNum(100, "Jungle Defender Spawn") < 5:
			pSpawnPlot = cf.findClearPlot(UnitTypes.NO_UNIT, pPlot)
			if pSpawnPlot != -1:
				lJList = ['UNIT_GOBLIN', 'UNIT_GOBLIN', 'UNIT_GOBLIN', 'UNIT_WOLF_RIDER', 'UNIT_LIZARDMAN', 'UNIT_LIZARDMAN', 'UNIT_LIZARDMAN', 'UNIT_LIZARDMAN', 'UNIT_LIZARDMAN_RANGER', 'UNIT_LIZARDMAN_ASSASSIN']
				sJungleDefender = lJList[CyGame().getSorenRandNum(len(lJList), "Pick Jungle Defender")]
				iJungleDefender = gc.getInfoTypeForString(sJungleDefender)
				eDirection = directionXYFromPlot(pSpawnPlot, pPlot)
				pBarbarianPlayer = gc.getPlayer(gc.getORC_PLAYER())
				pJungleDefender = pBarbarianPlayer.initUnit(iJungleDefender, pSpawnPlot.getX(), pSpawnPlot.getY(), UnitAITypes.NO_UNITAI, eDirection)
	if iFeature in iForestFeatures:
		if CyGame().getSorenRandNum(100, "Forest Defender Spawn") < 5:
			pSpawnPlot = cf.findClearPlot(UnitTypes.NO_UNIT, pPlot)
			if pSpawnPlot != -1:
				lFList = ['UNIT_WOLF', 'UNIT_WOLF', 'UNIT_WOLF', 'UNIT_WOLF', 'UNIT_WOLF', 'UNIT_WOLF_PACK', 'UNIT_WOLF_PACK', 'UNIT_WOLF_PACK', 'UNIT_BABY_SPIDER', 'UNIT_BABY_SPIDER', 'UNIT_BABY_SPIDER', 'UNIT_BABY_SPIDER', 'UNIT_BABY_SPIDER', 'UNIT_RAVENOUS_WEREWOLF', 'UNIT_GRIFFON', 'UNIT_BEAR','UNIT_BEAR', 'UNIT_FAWN', 'UNIT_FAWN', 'UNIT_FAWN', 'UNIT_FAWN', 'UNIT_FAWN', 'UNIT_SATYR']
				sForestDefender = lFList[CyGame().getSorenRandNum(len(lFList), "Pick Forest Defender")]
				iForestDefender = gc.getInfoTypeForString(sForestDefender)
				eDirection = directionXYFromPlot(pSpawnPlot, pPlot)
				pBarbarianPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
				pForestDefender = pBarbarianPlayer.initUnit(iForestDefender, pSpawnPlot.getX(), pSpawnPlot.getY(), UnitAITypes.NO_UNITAI, eDirection)
	# terraform the terrain
	if iTerrain == gc.getInfoTypeForString('TERRAIN_SNOW'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'), True, True)
	elif iTerrain == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'), True, True)
	elif iTerrain == gc.getInfoTypeForString('TERRAIN_GRASS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'), True, True)
	elif iTerrain == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'), True, True)
		if iFeature in iFlammableFeatures: 
			pPlot.setFeatureType(FeatureTypes.NO_FEATURE, -1)
			if CyGame().getSorenRandNum(100, "Scorch Scrub") < 20:
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_SCRUB'), -1)
		# add flood plains to new desert along rivers (delayed)
		if pPlot.canHaveFeature(gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')):
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS'), -1)
			pPlot.setTempFeatureType(FeatureTypes.NO_FEATURE, -1, cf.scale(5))
		# adds an oasis to some of the new deserts
		iOasis = gc.getInfoTypeForString('FEATURE_OASIS')
		if pPlot.canHaveFeature(iOasis):
			if CyGame().getSorenRandNum(10000, "Scorch Oasis") < gc.getFeatureInfo(iOasis).getAppearanceProbability():
				pPlot.setFeatureType(iOasis, -1)
	elif iTerrain == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'), True, True)
	# flammable features may catch fire and destroy built improvements
	if iFeature in iFlammableFeatures:
		if CyGame().getSorenRandNum(100, "Flames Spread") <= gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
			if iImprovement == ImprovementTypes.NO_IMPROVEMENT:
				pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
			elif not gc.getImprovementInfo(iImprovement).isPermanent():
				pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
	# declare war at plot owner
	if pPlot.isOwned():
		cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
# FlavourMod: End Change

def spellSing(caster):
	pPlot = caster.plot()
	point = pPlot.getPoint()
	iRnd = CyGame().getSorenRandNum(100, "Sing")
	szText = "AS3D_SING1"
	if iRnd > 25:
		szText = "AS3D_SING2"
	if iRnd > 50:
		szText = "AS3D_SING3"
	if iRnd > 75:
		szText = "AS3D_SING4"
	CyAudioGame().Play3DSound(szText,point.x,point.y,point.z)

def reqSironasTouch(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_HEAL_UNIT_PER_TURN) == false:
		return False
	if caster.getDamage() == 0:
		return False
	if pPlayer.isHuman() == False:
		if caster.getDamage() < 15:
			return False
	return True

def spellSironasTouch(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.setFeatAccomplished(FeatTypes.FEAT_HEAL_UNIT_PER_TURN, false)
	caster.changeDamage(-15,0)

def spellSlaveTradeBuy(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_SLAVE'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	iPromotion = -1
	iRnd = CyGame().getSorenRandNum(100, "Slave Trade Buy")
	if (iRnd >= 60 and iRnd < 70):
		iPromotion = gc.getInfoTypeForString('PROMOTION_DWARF')
	if (iRnd >= 70 and iRnd < 80):
		iPromotion = gc.getInfoTypeForString('PROMOTION_ELF')
	if (iRnd >= 80):
		iPromotion = gc.getInfoTypeForString('PROMOTION_ORC')
	if iPromotion != -1:
		newUnit.setHasPromotion(iPromotion, True)

def spellSnowfall(caster):
	iX = caster.getX()
	iY = caster.getY()
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if not pPlot.isWater():
					if pPlot.getTerrainType() != iSnow:
						iRnd = CyGame().getSorenRandNum(6, "Snowfall") + 3
# FlavourMod: Changed by Jean Elcard 03/30/2009 (FastRebuild)
						'''
						pPlot.setTempTerrainType(iSnow, iRnd)
						'''
						pPlot.setTempTerrainTypeFM(iSnow, iRnd, False, False)
# FlavourMod: End Change
						if pPlot.getFeatureType() == iFlames:
							pPlot.setFeatureType(-1, -1)
						if pPlot.getImprovementType() == iSmoke:
							pPlot.setImprovementType(-1)
# FlavourMod: Added by Jean Elcard 03/30/2009 (FastRebuild)
	cf.rebuildGraphics()
# FlavourMod: End Add

def spellSnowfallGreator(caster):
	iX = caster.getX()
	iY = caster.getY()
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if not pPlot.isWater():
					if pPlot.getTerrainType() != iSnow:
						iRnd = CyGame().getSorenRandNum(12, "Snowfall") + 6
# FlavourMod: Changed by Jean Elcard 03/30/2009 (FastRebuild)
						'''
						pPlot.setTempTerrainType(iSnow, iRnd)
						'''
						pPlot.setTempTerrainTypeFM(iSnow, iRnd, False, False)
# FlavourMod: End Change
						if pPlot.getFeatureType() == iFlames:
							pPlot.setFeatureType(-1, -1)
						if pPlot.getImprovementType() == iSmoke:
							pPlot.setImprovementType(-1)
# FlavourMod: Added by Jean Elcard 03/30/2009 (FastRebuild)
	cf.rebuildGraphics()
# FlavourMod: End Add

def reqSpreadTheCouncilOfEsus(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = caster.plot().getPlotCity()
	if pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS')):
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getStateReligion() != gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
			return False
	return True

def reqSpring(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	bFlames = false
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES') or pPlot2.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE'):
				bFlames = true
	if bFlames == False:
		if pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_DESERT'):
			return False
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS'):
			return False
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
	if pPlayer.isHuman() == False:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
			return False
	return True

def spellSpring(caster):
	pPlot = caster.plot()
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT') and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_SCRUB'):
			pPlot.setFeatureType(-1, -1)
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES'):
				pPlot2.setFeatureType(-1, -1)
			if pPlot2.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE'):
				pPlot2.setImprovementType(-1)

def reqSprint(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FATIGUED')):
		return False
	return True

def reqStasis(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
	return True

def spellStasis(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iDelay = 20
	iTeam = pPlayer.getTeam()
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
		iDelay = 14
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
		iDelay = 30
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
		iDelay = 60
	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		pPlayer2 = gc.getPlayer(iPlayer2)
		if pPlayer2.isAlive():
			if pPlayer2.getTeam() != iTeam:
				pPlayer2.changeDisableProduction(iDelay)
				pPlayer2.changeDisableResearch(iDelay)

def reqSteal(caster):
	iTeam = caster.getTeam()
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() != iTeam:
			for iProm in range(gc.getNumPromotionInfos()):
				if pUnit.isHasPromotion(iProm):
					if gc.getPromotionInfo(iProm).isEquipment():
						return True
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getTeam() != iTeam:
			for iBuild in range(gc.getNumBuildingInfos()):
				if pCity.getNumRealBuilding(iBuild) > 0:
					if gc.getBuildingInfo(iBuild).isEquipment():
						return True
	return False

def spellSteal(caster):
	iTeam = caster.getTeam()
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() != iTeam:
			for iProm in range(gc.getNumPromotionInfos()):
				if pUnit.isHasPromotion(iProm):
					if gc.getPromotionInfo(iProm).isEquipment():
 						if CyGame().getSorenRandNum(100, "Steal") <= 20:
							cf.startWar(caster.getOwner(), pUnit.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
						else:
							caster.setHasPromotion(iProm, True)
							pUnit.setHasPromotion(iProm, False)
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getTeam() != iTeam:
			for iBuild in range(gc.getNumBuildingInfos()):
				if pCity.getNumRealBuilding(iBuild) > 0:
					if gc.getBuildingInfo(iBuild).isEquipment():
 						if CyGame().getSorenRandNum(100, "Steal") <= 20:
							cf.startWar(caster.getOwner(), pUnit.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
						else:
							for iUnit in range(gc.getNumUnitInfos()):
								if gc.getUnitInfo(iUnit).getBuildings(iBuild):
									pCity.setNumRealBuilding(iBuild, 0)
									caster.setHasPromotion(gc.getUnitInfo(iUnit).getEquipmentPromotion(), True)

def reqTakeEquipmentBuilding(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	return True

def spellTakeEquipmentBuilding(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	pPlot = caster.plot()
	for i in range(gc.getNumBuildingInfos()):
		if gc.getUnitInfo(iUnit).getBuildings(i):
			pPlot.getPlotCity().setNumRealBuilding(i, 0)

def reqTakeEquipmentPromotion(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.isHasPromotion(iProm)):
			pHolder = pUnit
	if pHolder == -1:
		return False
	if pHolder.isHasCasted():
		return False
	if pHolder.getUnitType() == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		if iProm == gc.getInfoTypeForString('PROMOTION_PIECES_OF_BARNAXUS'):
			return False
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isHuman() == False:
		if caster.baseCombatStr() - 2 <= pHolder.baseCombatStr():
			return False
		if gc.getUnitInfo(pHolder.getUnitType()).getFreePromotions(iProm):
			return False
	return True

def spellTakeEquipmentPromotion(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.isHasPromotion(iProm) and pUnit != caster):
			pHolder = pUnit
	if pHolder != -1:
		pHolder.setHasPromotion(iProm, False)
		caster.setHasPromotion(iProm, True)

def reqTakeEquipmentUnit(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.getUnitType() == iUnit):
			if pUnit.isDelayedDeath() == False:
				pHolder = pUnit
	if pHolder == -1:
		return False
	return True

def spellTakeEquipmentUnit(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.getUnitType() == iUnit):
			if pUnit.isDelayedDeath() == False:
				pHolder = pUnit
	if pHolder != -1:
		pHolder.kill(True, PlayerTypes.NO_PLAYER)

def reqTaunt(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	bValid = False
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			for i in range(pLoopPlot.getNumUnits()):
				pUnit = pLoopPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					if pUnit.isAlive():
						if not pUnit.isOnlyDefensive():
							if pUnit.getImmobileTimer() == 0:
								bValid = True
	return bValid

def spellTaunt(caster):
	iEnraged = gc.getInfoTypeForString('PROMOTION_ENRAGED')
	iSpell = gc.getInfoTypeForString('SPELL_TAUNT')
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	bValid = False
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			for i in range(pLoopPlot.getNumUnits()):
				pUnit = pLoopPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					if pUnit.isAlive():
						if not pUnit.isOnlyDefensive():
							if pUnit.getImmobileTimer() == 0:
								if not pUnit.isResisted(caster, iSpell):
									pUnit.attack(pPlot, False)

def spellTeleport(caster,loc):
	player = caster.getOwner()
	pPlayer = gc.getPlayer(player)
	pCity = pPlayer.getCapitalCity()
	caster.setXY(pCity.getX(), pCity.getY(), false, true, true)

def reqTeachSpellcasting(caster):
	iAnimal = gc.getInfoTypeForString('UNITCOMBAT_ANIMAL')
	iBird = gc.getInfoTypeForString('SPECIALUNIT_BIRD')
	lList = []
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_AIR1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_BODY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_CHAOS1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DEATH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_EARTH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENTROPY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_FIRE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ICE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LAW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LIFE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_METAMAGIC1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_MIND1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_NATURE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SHADOW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SPIRIT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SUN1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_WATER1')]
##### Orbis
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')]
##### Orbis end
	if len(lList) > 0:
		pPlot = caster.plot()
		iPlayer = caster.getOwner()
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getOwner() == iPlayer:
				if pUnit.isAlive():
					if pUnit.getUnitCombatType() != iAnimal:
						if pUnit.getSpecialUnitType() != iBird:
							for iProm in range(len(lList)):
								if not pUnit.isHasPromotion(lList[iProm]):
									return True
	return False

def spellTeachSpellcasting(caster):
	iAnimal = gc.getInfoTypeForString('UNITCOMBAT_ANIMAL')
	iBird = gc.getInfoTypeForString('SPECIALUNIT_BIRD')
	iChanneling1 = gc.getInfoTypeForString('PROMOTION_CHANNELING1')
	lList = []
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_AIR1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_BODY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_CHAOS1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DEATH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_EARTH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENTROPY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_FIRE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ICE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LAW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LIFE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_METAMAGIC1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_MIND1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_NATURE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SHADOW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SPIRIT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SUN1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_WATER1')]
##### Orbis
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')]
##### Orbis end
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getOwner() == iPlayer:
			if pUnit.isAlive():
				if pUnit.getUnitCombatType() != iAnimal:
					if pUnit.getSpecialUnitType() != iBird:
						for iProm in range(len(lList)):
							if not pUnit.isHasPromotion(lList[iProm]):
								pUnit.setHasPromotion(lList[iProm], True)

def spellTreetopDefence(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() == caster.getTeam():
			pUnit.setFortifyTurns(5)

def reqTrust(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_TRUST):
		return False
	if pPlayer.isBarbarian():
		return False
	return True

def spellTrust(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = pPlayer.getCapitalCity()
	pPlayer.setFeatAccomplished(FeatTypes.FEAT_TRUST, true)

def spellTsunami(caster):
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if pPlot.isAdjacentToWater():
				if (iX != iiX or iY != iiY):
					for i in range(pPlot.getNumUnits()):
						pUnit = pPlot.getUnit(i)
						pUnit.doDamage(30, 75, caster, gc.getInfoTypeForString('DAMAGE_COLD'), true)
					if pPlot.getImprovementType() != -1:
						if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
							if CyGame().getSorenRandNum(100, "Tsunami") <= 25:
								pPlot.setImprovementType(-1)
					CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPRING'),pPlot.getPoint())

def spellUnyieldingOrder(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setOccupationTimer(0)
	pCity.changeHurryAngerTimer(-9)

def reqUpgradeDovielloWarrior(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.getNumCities() > pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_WORKER')):
			return False
	return True

def reqVeilOfNight(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getNumUnits() < 25:
			return False
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) > 0:
			return False
	return True

def spellVeilOfNight(caster):
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.baseCombatStr() > 0:
			pUnit.setHasPromotion(iHiddenNationality, True)

def reqVitalize(caster):
	pPlot = caster.plot()
	if pPlot.getOwner() != caster.getOwner():
		return False
	if pPlot.isWater():
		return false
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		return False
	return True

def spellVitalize(caster):
	pPlot = caster.plot()
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'):
		pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 1)
	if(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_SNOW')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_TUNDRA')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_DESERT')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_SCRUB'):			
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST_NEW'), 1)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_PLAINS')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'),True,True)

def reqWane(caster):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.isImmortal():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_SHADE')) >= 4:
		return False
	return True

def reqWarcry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getNumUnits() < 25:
			return False
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
	return True

def spellWarcry(caster):
	iWarcry = gc.getInfoTypeForString('PROMOTION_WARCRY')
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.getUnitCombatType() != -1:
			pUnit.setHasPromotion(iWarcry, True)

def reqWildHunt(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(iPlayer).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.getNumUnits() < 20:
			return False
	return True

def spellWildHunt(caster):
	iWolf = gc.getInfoTypeForString('UNIT_WOLF')
	pPlayer = gc.getPlayer(caster.getOwner())
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.baseCombatStr() > 0:
			newUnit = pPlayer.initUnit(iWolf, pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.setExperience(pUnit.getExperience() / 3, -1)
			if pUnit.baseCombatStr() > 3:
				i = (pUnit.baseCombatStr() - 2) / 2
				newUnit.setBaseCombatStr(2 + i)
			if pUnit.baseCombatStrDefense() > 3:
				i = (pUnit.baseCombatStrDefense() - 2) / 2
				newUnit.setBaseCombatStrDefense(2 + i)

def spellWonder(caster):
	iCount = CyGame().getSorenRandNum(3, "Wonder") + 3
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	bCity = False
	point = pPlot.getPoint()
	if pPlot.isCity():
		bCity = True
	for i in range (iCount):
		iRnd = CyGame().getSorenRandNum(66, "Wonder")
		iUnit = -1
		if iRnd == 0:
			caster.cast(gc.getInfoTypeForString('SPELL_BLAZE'))
		if iRnd == 1:
			caster.cast(gc.getInfoTypeForString('SPELL_BLESS'))
		if iRnd == 2:
			caster.cast(gc.getInfoTypeForString('SPELL_BLINDING_LIGHT'))
		if iRnd == 3:
			caster.cast(gc.getInfoTypeForString('SPELL_BLOOM'))
		if iRnd == 4:
			caster.cast(gc.getInfoTypeForString('SPELL_BLUR'))
		if iRnd == 5:
			caster.cast(gc.getInfoTypeForString('SPELL_CHARM_PERSON'))
		if iRnd == 6:
			caster.cast(gc.getInfoTypeForString('SPELL_CONTAGION'))
		if iRnd == 7:
			caster.cast(gc.getInfoTypeForString('SPELL_COURAGE'))
		if iRnd == 8:
			caster.cast(gc.getInfoTypeForString('SPELL_CRUSH'))
		if iRnd == 9:
			caster.cast(gc.getInfoTypeForString('SPELL_DESTROY_UNDEAD'))
		if iRnd == 10:
			caster.cast(gc.getInfoTypeForString('SPELL_DISPEL_MAGIC'))
		if iRnd == 11:
			caster.cast(gc.getInfoTypeForString('SPELL_EARTHQUAKE'))
		if iRnd == 12:
			caster.cast(gc.getInfoTypeForString('SPELL_ENCHANTED_BLADE'))
		if iRnd == 13:
			CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
			CyAudioGame().Play3DSound("AS3D_SPELL_DEFILE",point.x,point.y,point.z)
			for iX in range(pPlot.getX()-1, pPlot.getX()+2, 1):
				for iY in range(pPlot.getY()-1, pPlot.getY()+2, 1):
					pLoopPlot = CyMap().plot(iX,iY)
					if pLoopPlot.isNone() == False:
						pLoopPlot.changePlotCounter(100)
		if iRnd == 14:
			caster.cast(gc.getInfoTypeForString('SPELL_ENTANGLE'))
		if iRnd == 15:
			caster.cast(gc.getInfoTypeForString('SPELL_ESCAPE'))
		if iRnd == 16:
			caster.cast(gc.getInfoTypeForString('SPELL_FIREBALL'))
		if iRnd == 17:
			caster.cast(gc.getInfoTypeForString('SPELL_FLAMING_ARROWS'))
		if iRnd == 18:
			caster.cast(gc.getInfoTypeForString('SPELL_FLOATING_EYE'))
		if iRnd == 19:
			caster.cast(gc.getInfoTypeForString('SPELL_HASTE'))
		if iRnd == 20:
			caster.cast(gc.getInfoTypeForString('SPELL_HASTURS_RAZOR'))
		if iRnd == 21:
			caster.cast(gc.getInfoTypeForString('SPELL_HEAL'))
		if iRnd == 22:
			caster.cast(gc.getInfoTypeForString('SPELL_HIDE'))
		if iRnd == 23:
			caster.cast(gc.getInfoTypeForString('SPELL_LOYALTY'))
		if iRnd == 24:
			caster.cast(gc.getInfoTypeForString('SPELL_MAELSTROM'))
		if iRnd == 25:
			caster.cast(gc.getInfoTypeForString('SPELL_MORALE'))
		if iRnd == 26:
			caster.cast(gc.getInfoTypeForString('SPELL_MUTATION'))
		if iRnd == 27:
			caster.cast(gc.getInfoTypeForString('SPELL_PILLAR_OF_FIRE'))
		if iRnd == 28:
			caster.cast(gc.getInfoTypeForString('SPELL_POISONED_BLADE'))
		if iRnd == 29:
			caster.cast(gc.getInfoTypeForString('SPELL_REVELATION'))
		if iRnd == 30:
			caster.cast(gc.getInfoTypeForString('SPELL_RING_OF_FLAMES'))
		if iRnd == 31:
			caster.cast(gc.getInfoTypeForString('SPELL_RUST'))
		if iRnd == 32:
			caster.cast(gc.getInfoTypeForString('SPELL_SANCTIFY'))
		if iRnd == 33:
			caster.cast(gc.getInfoTypeForString('SPELL_SCORCH'))
		if iRnd == 34:
			caster.cast(gc.getInfoTypeForString('SPELL_SHADOWWALK'))
		if iRnd == 35:
			caster.cast(gc.getInfoTypeForString('SPELL_SPORES'))
		if iRnd == 36:
			caster.cast(gc.getInfoTypeForString('SPELL_SPRING'))
		if iRnd == 37:
			caster.cast(gc.getInfoTypeForString('SPELL_STONESKIN'))
		if iRnd == 38:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_AIR_ELEMENTAL'))
		if iRnd == 39:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_AUREALIS'))
		if iRnd == 40:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_BALOR'))
		if iRnd == 41:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_DJINN'))
		if iRnd == 42:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_EARTH_ELEMENTAL'))
		if iRnd == 43:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_EINHERJAR'))
		if iRnd == 44:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_FIRE_ELEMENTAL'))
		if iRnd == 45:
			iUnit = gc.getInfoTypeForString('UNIT_KRAKEN')
		if iRnd == 46:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_MISTFORM'))
		if iRnd == 47:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_PIT_BEAST'))
		if iRnd == 48:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_SAND_LION'))
		if iRnd == 49:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_SPECTRE'))
		if iRnd == 50:
			iUnit = gc.getInfoTypeForString('UNIT_TIGER')
		if iRnd == 51:
			iUnit = gc.getInfoTypeForString('UNIT_TREANT')
		if iRnd == 52:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_WATER_ELEMENTAL'))
		if iRnd == 53:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_WRAITH'))
		if iRnd == 54:
			caster.cast(gc.getInfoTypeForString('SPELL_TSUNAMI'))
		if iRnd == 55:
			caster.cast(gc.getInfoTypeForString('SPELL_VALOR'))
		if iRnd == 56:
			caster.cast(gc.getInfoTypeForString('SPELL_VITALIZE'))
		if iRnd == 57:
			caster.cast(gc.getInfoTypeForString('SPELL_WITHER'))
		if iRnd == 58:
			if bCity == False:
				iImprovement = pPlot.getImprovementType()
				bValid = True
				if iImprovement != -1 :
					if gc.getImprovementInfo(iImprovement).isPermanent() :
						bValid = False
				if bValid :
					pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PENGUINS'))
					CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_PENGUINS", ()),'',1,'Art/Interface/Buttons/Improvements/Penguins.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if iRnd == 59:
			if bCity == False:
				bValid = True
				if pPlot.getBonusType(-1) != -1:	
						bValid = False
				if bValid :
					pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MUSHROOMS'))
					CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_MUSHROOMS", ()),'',1,'Art/Interface/Buttons/Improvements/Mushrooms.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if iRnd == 60:
			for iProm in range(gc.getNumPromotionInfos()):
				if caster.isHasPromotion(iProm):
					if gc.getPromotionInfo(iProm).isRace():
						caster.setHasPromotion(iProm, False)
			caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_BABOON'))
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_BABOON", ()),'',1,'Art/Interface/Buttons/Units/Margalard.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			if pPlayer.isHuman():
				t = "TROPHY_FEAT_BABOON"
				if not CyGame().isHasTrophy(t):
					CyGame().changeTrophyValue(t, 1)
		if iRnd == 61:
			CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
			CyAudioGame().Play3DSound("AS3D_SPELL_SANCTIFY",point.x,point.y,point.z)
			for iX in range(pPlot.getX()-2, pPlot.getX()+3, 1):
				for iY in range(pPlot.getY()-2, pPlot.getY()+3, 1):
					pLoopPlot = CyMap().plot(iX,iY)
					if pLoopPlot.isNone() == False:
						pLoopPlot.changePlotCounter(-100)
		if iRnd == 62:
			iUnit = gc.getInfoTypeForString('UNIT_SPIDERKIN')
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_SPIDERKIN", ()),'',1,'Art/Interface/Buttons/Units/Spiderkin.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if iUnit != -1:
			newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')):
				newUnit.setDuration(2)
			else:
				newUnit.setDuration(1)
		if iRnd == 63:
			caster.cast(gc.getInfoTypeForString('SPELL_SLOW'))
		if iRnd == 64:
			caster.cast(gc.getInfoTypeForString('SPELL_SUMMON_ICE_ELEMENTAL'))
		if iRnd == 65:
			caster.cast(gc.getInfoTypeForString('SPELL_SNOWFALL'))

# FlavourMod: Added by Jean Elcard 03/30/2009 (FastRebuild)
	cf.rebuildGraphics()
# FlavourMod: End Add

def reqWorldbreak(caster):
	if CyGame().getGlobalCounter() == 0:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if CyGame().getGlobalCounter() < 50:
			return False
	return True

def spellWorldbreak(caster):
	iCounter = CyGame().getGlobalCounter()
	iFire = gc.getInfoTypeForString('DAMAGE_FIRE')
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
	iPillar = gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		bValid = True
		if pPlot.isOwned():
			if pPlot.getOwner() == caster.getOwner():
				bValid = False
		if bValid:
			if pPlot.isCity():
				if CyGame().getSorenRandNum(100, "Worldbreak") <= (iCounter / 4):
					cf.doCityFire(pPlot.getPlotCity())
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					pUnit.doDamage(iCounter, 100, caster, iFire, false)
				CyEngine().triggerEffect(iPillar,pPlot.getPoint())
			if (pPlot.getFeatureType() == iForest or pPlot.getFeatureType() == iJungle):
				if pPlot.getImprovementType() == -1:
					if CyGame().getSorenRandNum(100, "Flames Spread") <= (iCounter / 4):
						pPlot.setImprovementType(iSmoke)

def atRangeGuardian(pCaster, pPlot):
	if pPlot.getNumUnits() == 0:
		if CyGame().getStartTurn() + 20 < CyGame().getGameTurn(): #fixes a problem if units spawn next to the gargoyle
			iPlayer = pCaster.getOwner()
			if not gc.getPlayer(pCaster.getOwner()).isBarbarian():
				bPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
				iUnit = gc.getInfoTypeForString('UNIT_GARGOYLE')
				newUnit1 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit1.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				newUnit2 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit2.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				newUnit3 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit3.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GUARDIAN", ()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				pPlot.setPythonActive(False)

def atRangeJungleAltar(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.atRangeJungleAltar(pCaster, pPlot)

def atRangeNecrototem(pCaster, pPlot):
	if cf.doFear(pCaster, pPlot, -1, False):
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR", (gc.getUnitInfo(pCaster.getUnitType()).getDescription(), )),'',1,'Art/Interface/Buttons/Improvements/Necrototem.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)

def onMoveAncientForest(pCaster, pPlot):
	if pPlot.isOwned():
		if pPlot.getNumUnits() == 1:
			if pCaster.isFlying() == False:
				iChance = gc.getDefineINT('TREANT_SPAWN_CHANCE')
				if pPlot.isBeingWorked():
					pCity = pPlot.getWorkingCity()
					if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_TEMPLE_OF_LEAVES')) > 0:
						iChance = iChance * 3
				if CyGame().getSorenRandNum(100, "Treant Spawn Chance") <= iChance:
					pPlayer = gc.getPlayer(pCaster.getOwner())
					p2Player = gc.getPlayer(pPlot.getOwner())
					eTeam = gc.getTeam(pPlayer.getTeam())
					i2Team = p2Player.getTeam()
					if (eTeam.isAtWar(i2Team) and p2Player.getStateReligion() == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES')):
						for i in range(pPlot.getNumUnits()):
							p2Unit = pPlot.getUnit(i)
							p2Plot = cf.findClearPlot(p2Unit, -1)
							if p2Plot != -1:
								p2Unit.setXY(p2Plot.getX(),p2Plot.getY(), false, true, true)
								p2Unit.finishMoves()
						if pPlot.getNumUnits() == 0:
							newUnit = p2Player.initUnit(gc.getInfoTypeForString('UNIT_TREANT'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							newUnit.setDuration(3)
							CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TREANT_ENEMY",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Units/Treant.dds',ColorTypes(7),newUnit.getX(),newUnit.getY(),True,True)
							CyInterface().addMessage(pPlot.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TREANT",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Units/Treant.dds',ColorTypes(8),newUnit.getX(),newUnit.getY(),True,True)

def onMoveBlizzard(pCaster, pPlot):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WINTERBORN')) == False:
		pCaster.doDamage(10, 50, pCaster, gc.getInfoTypeForString('DAMAGE_COLD'), false)

def onMoveLetumFrigus(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isHuman():
		iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_LETUM_FRIGUS')
		triggerData = pPlayer.initTriggeredData(iEvent, true, -1, pCaster.getX(), pCaster.getY(), pCaster.getOwner(), -1, -1, -1, -1, -1)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LETUM_FRIGUS", ()),'',1,'Art/Interface/Buttons/Improvements/Letum Frigus.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		pPlot.setPythonActive(False)
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_LETUM_FRIGUS) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_LETUM_FRIGUS, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

			#More Events Mod Begins#	
		
def onMoveBrokenSepulcher(pCaster, pPlot) :
	if CyGame().getScenarioCounter()==6:
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA')):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA'), False)
			pPlayer = gc.getPlayer(pCaster.getOwner())
			for pyCity in PyPlayer(pCaster.getOwner()).getCityList() :
				pCity = pyCity.GetCy()
				if CyGame().getSorenRandNum(100, "Mane") <= 60:
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_MANES'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				if pCity.getPopulation() > 2:
					pCity.changePopulation(-2)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GELA_BROKEN", ()),'',1,'Art/Interface/Buttons/Improvements/Broken Sepulcher.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)


def onMoveMaelstrom(pCaster, pPlot):
	if CyGame().getScenarioCounter()==3:
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA')):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA'), False)
			pPlayer = gc.getPlayer(pCaster.getOwner())
			iProm = gc.getInfoTypeForString('PROMOTION_WATER_WALKING')
			if  pPlayer.getStateReligion() == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
				newUnit1 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_STYGIAN_GUARD'), pPlot.getX()+1, pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit1.setHasPromotion(iProm, True)
				newUnit2 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_STYGIAN_GUARD'), pPlot.getX()+1, pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit2.setHasPromotion(iProm, True)
				newUnit3 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_STYGIAN_GUARD'), pPlot.getX()+1, pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit3.setHasPromotion(iProm, True)
				newUnit4 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_STYGIAN_GUARD'), pPlot.getX()+1, pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit4.setHasPromotion(iProm, True)
				newUnit5 = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_DISCIPLE_OCTOPUS_OVERLORDS'), pPlot.getX()+1, pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit5.setHasPromotion(iProm, True)
				newUnit5.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO'), True)
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_GELA_1",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)
				pCaster.kill(True, PlayerTypes.NO_PLAYER)
			else:
				iStygianChance = 300
				bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
				for i in range (CyMap().numPlots()):
					pPlot = CyMap().plotByIndex(i)
					if  pPlot.isWater():
						if pPlot.getNumUnits() == 0:
							if CyGame().getSorenRandNum(10000, "Stygian") <= iStygianChance:			
								newUnit = bPlayer.initUnit(gc.getInfoTypeForString('UNIT_STYGIAN_GUARD'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
								newUnit.setHasPromotion(iProm, True)
				for i in range (CyMap().numPlots()):
					pPlot = CyMap().plotByIndex(i)
					if  pPlot.isWater():
						if pPlot.getNumUnits() == 0:
							if CyGame().getSorenRandNum(10000, "SeaSerpent") <= iStygianChance:			
								newUnit = bPlayer.initUnit(gc.getInfoTypeForString('UNIT_SEA_SERPENT'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
								newUnit.setHasPromotion(iProm, True)
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_GELA_2",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)
				pCaster.kill(True, PlayerTypes.NO_PLAYER)
		else:
			if CyGame().getSorenRandNum(100, "Maelstrom") <= 25:
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_KILL",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
				pCaster.kill(True, PlayerTypes.NO_PLAYER)
			else:
				iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
				iBestValue = 0
				pBestPlot = -1
				for i in range (CyMap().numPlots()):
					iValue = 0
					pTargetPlot = CyMap().plotByIndex(i)
					if pTargetPlot.getTerrainType() == iOcean:
						iValue = CyGame().getSorenRandNum(1000, "Maelstrom")
						if pTargetPlot.isOwned() == false:
							iValue += 1000
						if iValue > iBestValue:
							iBestValue = iValue
							pBestPlot = pTargetPlot
				if pBestPlot != -1:
					pCaster.setXY(pBestPlot.getX(), pBestPlot.getY(), false, true, true)
					pCaster.setDamage(25, PlayerTypes.NO_PLAYER)
					CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_MOVE",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)
	else:
		if CyGame().getSorenRandNum(100, "Maelstrom") <= 25:
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_KILL",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
			pCaster.kill(True, PlayerTypes.NO_PLAYER)
		else:
			iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
			iBestValue = 0
			pBestPlot = -1
			for i in range (CyMap().numPlots()):
				iValue = 0
				pTargetPlot = CyMap().plotByIndex(i)
				if pTargetPlot.getTerrainType() == iOcean:
					iValue = CyGame().getSorenRandNum(1000, "Maelstrom")
					if pTargetPlot.isOwned() == false:
						iValue += 1000
					if iValue > iBestValue:
						iBestValue = iValue
						pBestPlot = pTargetPlot
			if pBestPlot != -1:
				pCaster.setXY(pBestPlot.getX(), pBestPlot.getY(), false, true, true)
				pCaster.setDamage(25, PlayerTypes.NO_PLAYER)
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_MOVE",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)

def onMoveMirrorOfHeaven(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if CyGame().getWBMapScript():
		sf.onMoveMirrorOfHeaven(pCaster, pPlot)
	if CyGame().getScenarioCounter()==7 :
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA')):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA'), False)
			pCaster.changeImmobileTimer(6)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GELA_MIRROR",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Mirror Of Heaven.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SOL'), True)
			pPlayer = gc.getPlayer(pCaster.getOwner())
			iX = pPlot.getX()
			iY = pPlot.getY()
			iChampion = gc.getInfoTypeForString('UNIT_CHAMPION')
			iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
			iHellfire = gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE')
			bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
			for iPlayer2 in range(gc.getMAX_PLAYERS()):
				pPlayer2 = gc.getPlayer(iPlayer2)
				if (pPlayer2.isAlive()):
					if pPlayer2.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
						bPlayer = pPlayer2
						enemyTeam = bPlayer.getTeam()
						eTeam = gc.getTeam(pPlayer.getTeam())
						eTeam.declareWar(enemyTeam, true, WarPlanTypes.WARPLAN_TOTAL)
			for iiX in range(iX-2, iX+3, 1):
				for iiY in range(iY-2, iY+3, 1):
					pPlot2 = CyMap().plot(iiX,iiY)
					if not pPlot2.isWater():
						if pPlot2.getNumUnits() == 0:
							if not pPlot2.isCity():
								if pPlot2.isFlatlands():
									if CyGame().getSorenRandNum(500, "Hellfire") <= 400:
										iImprovement = pPlot2.getImprovementType()
										bValid = True
										if iImprovement != -1 :
											if gc.getImprovementInfo(iImprovement).isPermanent():
												bValid = False
										if bValid :
											pPlot2.setImprovementType(iHellfire)
											newUnit = bPlayer.initUnit(iChampion, pPlot2.getX(), pPlot2.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
											newUnit.setHasPromotion(iDemon, True)

	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_MIRROR_OF_HEAVEN) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_MIRROR_OF_HEAVEN, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMovePoolOfTears(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), false)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_DISEASED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), false)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_PLAGUED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), false)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_POISONED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), false)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_WITHERED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_RABIES')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RABIES'), false)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_RABIES",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if CyGame().getScenarioCounter()==2:
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA')):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA'), False)
			pPlayer = gc.getPlayer(pCaster.getOwner())
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PIKE_OF_TEARS'), True)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TEARS_GELA",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
			if pPlayer.getStateReligion() == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES'):
				if CyGame().getSorenRandNum(100, "Plague") <= 20:
					CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TEARS_GELA_PLAGUE",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
					for iPlayer2 in range(gc.getMAX_PLAYERS()):
						pPlayer2 = gc.getPlayer(iPlayer2)
					if pPlayer2.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
						for pyCity in PyPlayer(iPlayer2).getCityList() :
							pCity = pyCity.GetCy()
							i = CyGame().getSorenRandNum(5, "Blight")
							i += pCity.getPopulation() - 2
							i -= pCity.totalGoodBuildingHealth()
							pCity.changeEspionageHealthCounter(i)
							py = PyPlayer(iPlayer2)
							for pUnit in py.getUnitList():
								if pUnit.isAlive():
									pUnit.doDamageNoCaster(10, 100, gc.getInfoTypeForString('DAMAGE_DEATH'), false)
			else:
				if CyGame().getSorenRandNum(100, "Plague") <= 50:				
					CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TEARS_GELA_PLAGUE",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
					for iPlayer2 in range(gc.getMAX_PLAYERS()):
						pPlayer2 = gc.getPlayer(iPlayer2)
					if pPlayer2.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
						for pyCity in PyPlayer(iPlayer2).getCityList() :
							pCity = pyCity.GetCy()
							i = CyGame().getSorenRandNum(5, "Blight")
							i += pCity.getPopulation() - 2
							i -= pCity.totalGoodBuildingHealth()
							pCity.changeEspionageHealthCounter(i)
							py = PyPlayer(iPlayer2)
							for pUnit in py.getUnitList():
								if pUnit.isAlive():
									pUnit.doDamageNoCaster(10, 100, gc.getInfoTypeForString('DAMAGE_DEATH'), false)
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_POOL_OF_TEARS) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_POOL_OF_TEARS, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMovePyreOfTheSeraphic(pCaster, pPlot):
	if CyGame().getScenarioCounter()==5 :
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA')):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GELA'), False)
			pPlayer = gc.getPlayer(pCaster.getOwner())
			if CyGame().getSorenRandNum(100, "Pyre") <= 40:
				pPlot.setImprovementType(-1)
				pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FROZEN_FLAME'), True)
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TEARS_GELA_PYRE_1",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pyre of the Seraphic.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
			else:  
				pPlot.setImprovementType(-1)
				i = 4
				if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_DUEL'):
					i = i - 3
				if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_TINY'):
					i = i - 2
				if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_SMALL'):
					i = i - 1
				if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_LARGE'):
					i = i + 1
				if CyMap().getWorldSize() == gc.getInfoTypeForString('WORLDSIZE_HUGE'):
					i = i + 3
				cf.addBonus('BONUS_MANA',i,'Art/Interface/Buttons/WorldBuilder/mana_button.dds')
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TEARS_GELA_PYRE_2",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pyre of the Seraphic.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
					
	#More Events Mod ends	
def onMoveJungleAltar(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMoveJungleAltar(pCaster, pPlot)

def onMovePortal(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMovePortal(pCaster, pPlot)

def onMoveWarningPost(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMoveWarningPost(pCaster, pPlot)

def voteFundDissidents():
	iOvercouncil = gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.isAlive():
			if pPlayer.isFullMember(iOvercouncil):
				for pyCity in PyPlayer(iPlayer).getCityList() :
					if CyGame().getSorenRandNum(100, "Fund Dissidents") < 50:
						pCity = pyCity.GetCy()
						pCity.changeHurryAngerTimer(1 + CyGame().getSorenRandNum(3, "Fund Dissidents"))

##### ORBI
def checkLycanthropy(pCaster):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WEREWOLF')) == False:
		if CyGame().getSorenRandNum(9, "Werewolf") < 1:
			pCaster.cast(gc.getInfoTypeForString('SPELL_BLOOD_MOON'))

def checkdeLycanthropy(pCaster):
	if CyGame().getSorenRandNum(9, "Werewolf") < 1:
		pCaster.cast(gc.getInfoTypeForString('SPELL_HUMAN_FORM'))

def reqElephant(caster):
	pPlot = caster.plot()
	if pPlot.getOwner() != caster.getOwner():
		return False
	if pPlot.getBonusType(-1) != -1:
		return False
	if pPlot.isCity() == True:
		return false
	if pPlot.isWater():
		return false
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		return False
	if caster.isBarbarian():
		return False			
	return True

def spellElephant(caster):
	pPlot = caster.plot()
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_IVORY'))

def spellMonsoon(caster):
	iPlayer = caster.getOwner()
	iTeam = caster.getTeam()
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iLight = gc.getInfoTypeForString('DAMAGE_LIGHTNING')
	iJungle = gc.getInfoTypeForString('FEATURE_DEEP_JUNGLE')
	iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
	iSwamp = gc.getInfoTypeForString('FEATURE_SWAMP')
	iLizard = gc.getInfoTypeForString('CIVILIZATION_MAZATL')
	iStorm = gc.getInfoTypeForString('EFFECT_WATER_SUMMON')
	iGrassChance = 20
	pPlayer = gc.getPlayer(iPlayer)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		iTerrain = pPlot.getTerrainType()
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				if pPlot.getFeatureType() == iFlames:
					pPlot.setFeatureType(-1, 0)
				if pPlot.getImprovementType() == iSmoke:
					pPlot.setImprovementType(-1)
				if iTerrain == iGrass and pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST'):		
					pPlot.setFeatureType(iJungle, 0)
				if iTerrain == iGrass and pPlot.isHills() == False and pPlot.getFeatureType() == -1 and pPlot.isCity() == false:
					iChance = iGrassChance
					if pPlot.isRiverSide() == True:
						iChance = iGrassChance * 4
					if CyGame().getSorenRandNum(100, "Grass") < iChance :
						pPlot.setFeatureType(iSwamp, 0)	
						pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_MARSH'),True,True)	
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getCivilizationType() != iLizard:
						pUnit.doDamageNoCaster(60, 80, iLight, false)
				if pPlot.isVisibleToWatchingHuman():
					CyEngine().triggerEffect(iStorm,pPlot.getPoint())

def spellHealingPotion(caster):
	caster.setDamage(0, caster.getOwner())
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RABIES'), false)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), false)
	if (CyGame().getSorenRandNum(10, "Potion run out chance") < 3):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEALING_POTION'), False)

def reqProspecting(caster):
	pPlot = caster.plot()
	if pPlot.isCity() == True:
		return False
	if pPlot.isHills() == False:
		return False
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		pPlot2 = CyMap().plot(iiX,iY)
		if pPlot2.isWater() == False:
			if pPlot2.getBonusType(-1) != -1:
				return False
	for iiY in range(iY-1, iY+2, 1):
		pPlot2 = CyMap().plot(iX,iiY)
		if pPlot2.isWater() == False:
			if pPlot2.getBonusType(-1) != -1:
				return False
	return True

def spellProspecting(caster):
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair")
	iDestroyLair = 0
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	if caster.isHasPromotion(iAdventurer):
		iRnd += 5

	if iRnd < 5:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 5 and iRnd < 31:
		iDestroyLair = cf.ProspBad(caster)
	if iRnd >= 31 and iRnd < 51:
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_NOTHING'), caster)
	if iRnd >= 51 and iRnd < 71:
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_PROSPECTING_MONEY'), caster)
	if iRnd >= 71:
		iDestroyLair = cf.Prospecting(caster)
	caster.finishMoves()

def reqBreeding(caster):
	pPlot = caster.plot()
	if pPlot.isCity() == True:
		return False
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		pPlot2 = CyMap().plot(iiX,iY)
		if pPlot2.isWater() == False:
			if pPlot2.getBonusType(-1) != -1:
				return False
	for iiY in range(iY-1, iY+2, 1):
		pPlot2 = CyMap().plot(iX,iiY)
		if pPlot2.isWater() == False:
			if pPlot2.getBonusType(-1) != -1:
				return False
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_FARM'):
		return True
	if (pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_PLAINS') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_GRASS') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_MARSH') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_SHALLOWS')):
		return False
	return True

def spellBreeding(caster):
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair")
	iDestroyLair = 0
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	if caster.isHasPromotion(iAdventurer):
		iRnd += 5

	if iRnd < 5:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 5 and iRnd < 31:
		iDestroyLair = cf.ProspBad(caster)
	if iRnd >= 31 and iRnd < 51:
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_NOTHING'), caster)
	if iRnd >= 51 and iRnd < 71:
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_BREEDING_MONEY'), caster)
	if iRnd >= 71:
		iDestroyLair = cf.Breeding(caster)
	caster.finishMoves()

def reqSteamworks(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_WORKSHOP')) < 5:
			return False
	return True

def spellSteamworks(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	eTeam = gc.getTeam(pPlayer.getTeam())
	iTech = pPlayer.getCurrentResearch()
	iNum = 20 + (pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_WORKSHOP')) * 60) + (pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_WATERMILL')) * 50) + (pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_WINDMILL')) * 50)
	eTeam.changeResearchProgress(iTech, iNum, caster.getOwner())

def reqCreateNest(caster):
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_GRIFFIN_NEST')
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-5, iX+6, 1):
		for iiY in range(iY-5, iY+6, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateNest(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_GRIFFIN_NEST')
	iUnit = gc.getInfoTypeForString('UNIT_GRIFFON')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenWolf(caster):
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_WOLF')
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenWolf(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_WOLF')
	iUnit = gc.getInfoTypeForString('UNIT_WOLF')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenTiger(caster):
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_TIGER')
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenTiger(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_TIGER')
	iUnit = gc.getInfoTypeForString('UNIT_TIGER')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenGorilla(caster):
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_GORILLA')
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenGorilla(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_GORILLA')
	iUnit = gc.getInfoTypeForString('UNIT_GORILLA')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenSpider(caster):
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_SPIDER')
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, PlayerTypes(caster.getOwner()), true) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-6, iX+7, 1):
		for iiY in range(iY-6, iY+7, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if pPlot2.getImprovementType() == iImprovement:
				return False
	return True

def spellCreateDenSpider(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_DEN_SPIDER')
	iUnit = gc.getInfoTypeForString('UNIT_GIANT_SPIDER')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), false, true, true)
		pPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)


def spellHauntRuins(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_HAUNTED_RUINS')
	pPlot.setImprovementType(iImprovement)

def reqClaimFort(caster):
	iUnitFortCommander = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_FORT_COMMANDER')
	pPlot = caster.plot()
	for iUnitLoop in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(iUnitLoop)			
			# Can't cast if another commander is there
		if pUnit.getUnitType() == iUnitFortCommander:
			return false
	if pPlot.isOwned():
		if pPlot.getOwner() != caster.getOwner():
			pPlayer = gc.getPlayer(caster.getOwner())
			eTeam = gc.getTeam(pPlayer.getTeam())
			p2Player = gc.getPlayer(pPlot.getOwner())
			e2Team = p2Player.getTeam()
			if eTeam.isAtWar(e2Team) == False:
				return false
	return true

def spellClaimFort(pCaster):
	pPlot = pCaster.plot()
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FORT_COMMANDER'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def checkFort(pCaster):
	pPlot = pCaster.plot()
	if (pPlot.getImprovementType() != gc.getInfoTypeForString('IMPROVEMENT_FORT') and pPlot.getImprovementType() != gc.getInfoTypeForString('IMPROVEMENT_KEEP') and pPlot.getImprovementType() != gc.getInfoTypeForString('IMPROVEMENT_CASTLE')):
		pCaster.kill(True, PlayerTypes.NO_PLAYER)

def checkDaring(pCaster):
	pPlot = pCaster.plot()
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_OCEAN'):
		if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_HOLK'):
			if CyGame().getSorenRandNum(100, "DaringRisk") < 10:
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DARING_SUNK", ()),'',1,'Art/Interface/Buttons/Promotions/Daring.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
				pCaster.kill(True, PlayerTypes.NO_PLAYER)
		if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_LANGSKIP'):
			if CyGame().getSorenRandNum(100, "DaringRisk") < 20:
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DARING_SUNK", ()),'',1,'Art/Interface/Buttons/Promotions/Daring.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
				pCaster.kill(True, PlayerTypes.NO_PLAYER)

def reqExploreDen(caster):
	if caster.isOnlyDefensive():
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
		return False
	if caster.isBarbarian():
		return False
	if caster.getDuration() > 0:
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_BIRD'):
		return False
	pPlot = caster.plot()
	if not pPlot.isWater():
		pPlayer = gc.getPlayer(caster.getOwner())
		iTeam = pPlayer.getTeam()
		eTeam = gc.getTeam(iTeam)
		bPlayer = gc.getPlayer(gc.getANIMAL_PLAYER())
		if not eTeam.isAtWar(bPlayer.getTeam()):
			return False
	return True

def spellExploreDen(caster):
	pPlot = caster.plot()
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair")
	iDestroyLair = 0
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	if caster.isHasPromotion(iAdventurer):
		iRnd += 10

	if iRnd < 24:
		iDestroyLair = cf.exploreDenBigBad(caster)
	if iRnd >= 24 and iRnd < 65:
		iDestroyLair = cf.exploreDenBad(caster)
	if iRnd >= 65 and iRnd < 95:
		iDestroyLair = cf.exploreDenGood(caster)
	if iRnd >= 95:
		iDestroyLair = cf.exploreLairBigGood(caster)
	if iDestroyLair > CyGame().getSorenRandNum(100, "Explore Lair"):
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LAIR_DESTROYED", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		pPlot.setImprovementType(-1)
	caster.finishMoves()

# Scions start
# Spell for Awakened and Reborn 
def reqAddPop(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if (pCity.happyLevel() - pCity.unhappyLevel(0)) < 1:
		return False
	return True

# Haunted lands creation
def reqHauntedLands(caster):
	pPlot = caster.plot()
	if pPlot.isWater():
		return False
	if pPlot.isPeak():
		return False
	if pPlot.isCity():
		return False
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_VOLCANO'):
		return False
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS'):
		return False
	return True

def spellHauntedLands(caster):
	iHaunted= gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS')
	iForest= gc.getInfoTypeForString('FEATURE_FOREST')
	iAnForest= gc.getInfoTypeForString('FEATURE_ANCIENT_FOREST')
	iJungle= gc.getInfoTypeForString('FEATURE_JUNGLE')
	iDpJungle= gc.getInfoTypeForString('FEATURE_DEEP_JUNGLE')
	pPlot = caster.plot()
	iX = caster.getX()
	iY = caster.getY()
	pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'),0)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if (pLoopPlot.isWater() == false and pLoopPlot.isCity() == false and pLoopPlot.isPeak() == False and pLoopPlot.isCity() == False):
				if (pLoopPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_VOLCANO') and pLoopPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')):
					if ((pLoopPlot.getFeatureType() != iForest and pLoopPlot.getFeatureType() != iJungle and pLoopPlot.getFeatureType() != iAnForest and pLoopPlot.getFeatureType() != iDpJungle) and (CyGame().getSorenRandNum(10, "Chance") > 3)):
						pLoopPlot.setFeatureType(iHaunted,0)
					if ((pLoopPlot.getFeatureType() == iForest or pLoopPlot.getFeatureType() == iJungle) and (CyGame().getSorenRandNum(10, "Chance") > 5)):
						pLoopPlot.setFeatureType(iHaunted,0)
					if ((pLoopPlot.getFeatureType() == iAnForest or pLoopPlot.getFeatureType() == iDpJungle) and (CyGame().getSorenRandNum(10, "Chance") > 8)):
						pLoopPlot.setFeatureType(iHaunted,0)

# "Feed" spell - Ghostwalkers gets damaged to allow Creepers to create HauntedLands, Creeper starts blooming	
def spellFeedCreeper(caster):
	pPlot = caster.plot()
	iHaunted= gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS')
	iForest= gc.getInfoTypeForString('FEATURE_FOREST')
	iAnForest= gc.getInfoTypeForString('FEATURE_ANCIENT_FOREST')
	iJungle= gc.getInfoTypeForString('FEATURE_JUNGLE')
	iDpJungle= gc.getInfoTypeForString('FEATURE_DEEP_JUNGLE')
	caster.setDamage(80, PlayerTypes.NO_PLAYER)
	iX = caster.getX()
	iY = caster.getY()
	pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_HAUNTED_LANDS'),0)
	iCreeper = gc.getInfoTypeForString('UNIT_CREEPER')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iCreeper:
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BLOOMING_CREEPER'), True)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if (pLoopPlot.isWater() == false and pLoopPlot.isCity() == false and pLoopPlot.isPeak() == False and pLoopPlot.isCity() == False):
				if (pLoopPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_VOLCANO') and pLoopPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')):
					if ((pLoopPlot.getFeatureType() != iForest and pLoopPlot.getFeatureType() != iJungle and pLoopPlot.getFeatureType() != iAnForest and pLoopPlot.getFeatureType() != iDpJungle) and (CyGame().getSorenRandNum(10, "Chance") > 3)):
						pLoopPlot.setFeatureType(iHaunted,0)
					if ((pLoopPlot.getFeatureType() == iForest or pLoopPlot.getFeatureType() == iJungle) and (CyGame().getSorenRandNum(10, "Chance") > 5)):
						pLoopPlot.setFeatureType(iHaunted,0)
					if ((pLoopPlot.getFeatureType() == iAnForest or pLoopPlot.getFeatureType() == iDpJungle) and (CyGame().getSorenRandNum(10, "Chance") > 8)):
						pLoopPlot.setFeatureType(iHaunted,0)

def CreeperSpawn(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_CREEPER'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def checkBurrs(pCaster):
	pPlot = pCaster.plot()
	if CyGame().getSorenRandNum(10, "BurrsHatching") < 3:
		if (pCaster.getLevel() >= 6 or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO')) or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ADVENTURER')) or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LEADER'))):
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_BURRS_SURVIVED", ()),'',1,'Art/Interface/Buttons/Promotions/Burrs.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
			pCaster.setDamage(75, PlayerTypes.NO_PLAYER)
		else:
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_BURRS_DESTROYED", ()),'',1,'Art/Interface/Buttons/Promotions/Burrs.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
			pCaster.kill(True, PlayerTypes.NO_PLAYER)
			newUnit = gc.getPlayer(gc.getANIMAL_PLAYER()).initUnit(gc.getInfoTypeForString('UNIT_CREEPER'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.changeExperience(pCaster.getExperience() / 2, -1, false, false, false, false)

def checkHaunt(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isBarbarian():
		return
	if CyGame().getSorenRandNum(4, "Check") >= 1:
		return
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HAUNT'), False)

def spellManifestHornedDread(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	py = PyPlayer(caster.getOwner())
	iHornedDreadPromo = gc.getInfoTypeForString('PROMOTION_HORNED_DREAD')
	for pUnit in py.getUnitList():
		if pUnit.isHasPromotion(iHornedDreadPromo):
			pUnit.setHasPromotion(iHornedDreadPromo, false)
	caster.setHasPromotion(iHornedDreadPromo, true)				

# Req for Give Gift spell. 
def reqEmbraceGift(pCaster):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO')):
		return False
	if pCaster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_KORRINA'):
		return False
	return True

def reqMelanteResidence(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = caster.plot().getPlotCity()
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ONE_CITY_CHALLENGE):
		return True
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_PALACE_SCIONS')) > 0:
		return False
	return True

#Thaumaturge's Keep	
def reqThaumaturge(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = caster.plot().getPlotCity()
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ONE_CITY_CHALLENGE):
		return True
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_PALACE_SCIONS')) > 0:
		return False
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_BUILT_KEEP) == true:
		return False
	return True

# Sets up the Thaumaturge's Keep campus.	
def spellThaumaturge(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.setFeatAccomplished(FeatTypes.FEAT_BUILT_KEEP, true)
	pCity = caster.plot().getPlotCity()

	iChance = CyGame().getSorenRandNum(8, "Chance")
	if iChance == 0:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_BODY'), 1)
	if iChance == 1:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_LAW'), 1)
	if iChance == 2:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ENCHANTMENT'), 1)
	if iChance == 3:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_EARTH'), 1)
	if iChance == 4:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ENTROPY'), 1)
	if iChance == 5:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_MIND'), 1)
	if iChance == 6:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ICE'), 1)
	if iChance == 7:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_SHADOW'), 1)
	if iChance == 8:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_CHAOS'), 1)
	iChance2 = CyGame().getSorenRandNum(8, "Chance")
	if iChance2 == 0:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_BODY'), 1)
	if iChance2 == 1:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_LAW'), 1)
	if iChance2 == 2:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ENCHANTMENT'), 1)
	if iChance2 == 3:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_EARTH'), 1)
	if iChance2 == 4:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ENTROPY'), 1)
	if iChance2 == 5:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_MIND'), 1)
	if iChance2 == 6:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ICE'), 1)
	if iChance2 == 7:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_SHADOW'), 1)
	if iChance2 == 8:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_CHAOS'), 1)

	iChance3 = CyGame().getSorenRandNum(3, "Chance3")
	if iChance3 <= 0:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_MILITARY_ABATTOIR'), 1)
	if iChance3 <= 1:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ALCHEMIST'), 1)
	if iChance3 <= 2:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_SCHOLA_FURIO'), 1)
	if iChance3 <= 3:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALCINUS_TROVE'), 1)
	iChance4 = CyGame().getSorenRandNum(3, "Chance4")
	if iChance4 <= 0:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_MILITARY_ABATTOIR'), 1)
	if iChance4 <= 1:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_KEEP_ALCHEMIST'), 1)
	if iChance4 <= 2:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_SCHOLA_FURIO'), 1)
	if iChance4 <= 3:
		pCity.setNumRealBuilding(gc.getInfoTypeForString('BUILDING_ALCINUS_TROVE'), 1)

def reqDarkCouncil(caster):
	pPlot = caster.plot()
	iPelemoc = gc.getInfoTypeForString('UNIT_PELEMOC')
	iThemoch = gc.getInfoTypeForString('UNIT_THEMOCH')
	iAlcinus = gc.getInfoTypeForString('UNIT_ALCINUS')	
	bPelemocPresent = false
	bThemochPresent = false
	bAlcinusPresent = false
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iPelemoc:
			bPelemocPresent = true
		if pUnit.getUnitType() == iThemoch:
			bThemochPresent = true
		if pUnit.getUnitType() == iAlcinus:
			bAlcinusPresent = true			
	if bPelemocPresent and bThemochPresent and bAlcinusPresent:
		return true
	return False

def spellSeekAlcinus(caster):
	iAlcinus = gc.getInfoTypeForString('UNIT_ALCINUS')	
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		py = PyPlayer(iPlayer)
		if (pPlayer.isAlive()):
			for pUnit in py.getUnitList():	
				if pUnit.getUnitType() == iAlcinus:
					pPlot = pUnit.plot()
					pPlayer = gc.getPlayer(caster.getOwner())
					iTeam = pPlayer.getTeam()
					pPlot.setRevealed(iTeam, True, False, TeamTypes.NO_TEAM)
					CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("We have found the traitor!", ()),'',1,', ,Art/unique_Atlas.dds,7,6',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)

def postAlcinusDeath(caster):
	if CyGame().GetWorldBuilderMode():
		return 0
	bContinue = True
	if CyGame().getSorenRandNum(100, "Alcinus death defection Check") <= 25:
		for iPlayer in range(gc.getMAX_CIV_PLAYERS()):
			pPlayer = gc.getPlayer(iPlayer)
			if (pPlayer.isAlive()):
				if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SCIONS'):
					pCity = pPlayer.getCapitalCity()
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ALCINUS'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					caster.setDamage(95, -1)
					newUnit.convert(caster)
					bContinue = False
	if bContinue:
		listPlayers = []
		for iPlayer in range(gc.getMAX_CIV_PLAYERS()):
			pPlayer = gc.getPlayer(iPlayer)
			if (pPlayer.isAlive()):
				listPlayers.append(pPlayer)
		iGift = CyGame().getSorenRandNum(len(listPlayers), "Who gets Alcinus Gift")
		pCity = listPlayers[iGift].getCapitalCity()
		pPlayer = listPlayers[iGift]
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ALCINUS'), pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		caster.setDamage(95, -1)
		newUnit.convert(caster)
	return 1

def reqEcult(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pCity.getOwner() == caster.getOwner():
		return False
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_SCIONS_SYMPATHISERS')) > 0:
		return False
	return True

def reqSuccor(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUH = pCity.goodHealth() - pCity.badHealth(False)
	if pCity.getOwner() == caster.getOwner():
		return False
	if iUH > -2:
		return False
	return True
	
def spellSuccor(caster,loc):
	pPlot = caster.plot()	
	player = caster.getOwner()
	pPlayer = gc.getPlayer(player)
	pCity = pPlayer.getCapitalCity()
	iReborn = gc.getInfoTypeForString('UNIT_REBORN')
	spawnUnit = pPlayer.initUnit(iReborn, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def MartyrSuicide(pCaster, pOpponent):
	if (pOpponent.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_HAWK')):
		return
	if (pOpponent.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_WORKER')):
		return
	if CyGame().getSorenRandNum(3, "Check") > 1:
		pCaster.kill(True, 0)

def reqMend(caster):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	iPoisoned = gc.getInfoTypeForString('PROMOTION_POISONED')
	iWither = gc.getInfoTypeForString('PROMOTION_WITHERED')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isHasPromotion(iUndead) and pUnit.getDamage() > 0):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				return True
		if pUnit.isHasPromotion(iPoisoned):
			return True
		if pUnit.isHasPromotion(iWither):
			return True
	return False

def spellMend(caster,amount):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iUndead):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				pUnit.changeDamage(-amount,0) #player doesn't matter - it won't kill

def effectGrandWard(caster):
	caster.cast(gc.getInfoTypeForString('SPELL_GRAND_WARD'))

def reqReplenish(caster):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isHasPromotion(iUndead) and pUnit.getDamage() > 0):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				return True
	return False

def spellReplenish(caster):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iUndead):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REPLENISHING'), True)
def reqUntiring(caster):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iUndead):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNTIRING')) == False:
					return True
	return False

def spellUntiring(caster):
	pPlot = caster.plot()
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iUndead):
			if (pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_BONE_HORDE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_DISEASED_CORPSE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SKELETON') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_SPECTRE') and pUnit.getUnitType() != gc.getInfoTypeForString('UNIT_WRAITH')):
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNTIRING'), True)

def onMovePatria(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_REMNANTS_OF_PATRIA) == false:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_SCIONS"):
			iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_REMNANTS_OF_PATRIA_SCIONS')
			triggerData = pPlayer.initTriggeredData(iEvent, true, -1, pCaster.getX(), pCaster.getY(), -1, -1, -1, -1, -1, -1)
			pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_REMNANTS_OF_PATRIA, True)
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_REMNANTS_OF_PATRIA, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveDragonBones(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_DRAGON_BONES) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_DRAGON_BONES, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveOdiosPrison(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_ODIOS_PRISON) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_ODIOS_PRISON, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveSevenPines(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_SEVEN_PINES) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_SEVEN_PINES, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveStandingStones(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_STANDING_STONES) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_STANDING_STONES, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveTombSucellus(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_TOMB_OF_SUCELLUS) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_TOMB_OF_SUCELLUS, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveYggdrasil(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_YGGDRASIL) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_YGGDRASIL, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveGateUnderdark(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_GATE_UNDERDARK) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_GATE_UNDERDARK, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def onMoveMountKalshekk(pCaster, pPlot):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_VISIT_MOUNT_KALSHEKK) == false:
		if pPlayer.isFeatAccomplished(FeatTypes.FEAT_ELOHIM_PILGRIMAGE_COMPLETED) == false:
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ELOHIM"):
				pPlayer.setFeatAccomplished(FeatTypes.FEAT_VISIT_MOUNT_KALSHEKK, True)
				iPilgrimage = cf.ElohimPilgrimage(pCaster)

def reqAcademyTraining(pCaster):
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_MELEE'):
		return True
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_MOUNTED'):
		return True
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ARCHER'):
		return True
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return True
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return True
	if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_PALADIN'):
		return True
	if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_EIDOLON'):
		return True
	if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_PARAMANDER'):
		return True
	return False

def postCombatDoviello(pCaster, pOpponent):
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	if pOpponent.isHasPromotion(iBronze):
		if gc.getUnitInfo(pCaster.getUnitType()).getWeaponTier() >= 1:
			pCaster.setHasPromotion(iBronze, True)
	elif pOpponent.isHasPromotion(iIron):
		if gc.getUnitInfo(pCaster.getUnitType()).getWeaponTier() >= 2:
			pCaster.setHasPromotion(iIron, True)
	elif pOpponent.isHasPromotion(iMithril):
		if gc.getUnitInfo(pCaster.getUnitType()).getWeaponTier() >= 3:
			pCaster.setHasPromotion(iMithril, True)

def reqChallengeAnimal(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(gc.getPlayer(gc.getANIMAL_PLAYER()).getTeam())
	if eTeam.isAtWar(iTeam) == false:
		iX = caster.getX()
		iY = caster.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
						if pUnit.getOwner() == gc.getANIMAL_PLAYER():
							return True
	return False

def reqChallengeBeast(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(gc.getPlayer(gc.getANIMAL_PLAYER()).getTeam())
	if eTeam.isAtWar(iTeam) == false:
		iX = caster.getX()
		iY = caster.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
						if pUnit.getOwner() == gc.getANIMAL_PLAYER():
							return True
	return False

def spellConvertWarg(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARG'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.convert(caster)
	if caster.baseCombatStr() > 3:
		i = (caster.baseCombatStr() - 3)
		newUnit.setBaseCombatStr(5 + i)
	if caster.baseCombatStrDefense() > 3:
		i = (caster.baseCombatStrDefense() - 3)
		newUnit.setBaseCombatStrDefense(5 + i)

def onMoveCarcer(caster, pPlot):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	if (caster.getLevel() > 14):
		eTeam = gc.getTeam(gc.getPlayer(gc.getDEMON_PLAYER()).getTeam())
		if eTeam.isAtWar(iTeam) == true:
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BRIGIT'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			pPlot.setImprovementType(-1)
			if pPlot.isVisibleToWatchingHuman():
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_ICE_SUMMON'),pPlot.getPoint())
				CyAudioGame().Play3DSound("AS3D_SPELL_TSUNAMI",pPlot.getPoint().x,pPlot.getPoint().y,pPlot.getPoint().z)
			if pPlayer.isHuman():
				t = "TROPHY_FEAT_RESCUE_BRIGIT"
				if not CyGame().isHasTrophy(t):
					CyGame().changeTrophyValue(t, 1)

# NGOMELE START [v0.5]; 20/05/09 (d/m/y)
##
# I. Heroes checks
#-- The two heroes get a bonus whenever they are on the same tile:
#-a.- checkIsComplete() checks if the other hero is on the tile; requires the Lonely promotion
#-b.- checkIsLonely() checks if the other hero has left the tile; requires the Complete promotion
##
def checkIsComplete(pCaster):
	pPlot = pCaster.plot()
	iBanung = gc.getInfoTypeForString('UNIT_BANUNG_THE_BLIND')
	iNga = gc.getInfoTypeForString('UNIT_NGA_EYE_EATER')
	if pCaster.getUnitType() == iNga:
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if (pCaster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iBanung):
				pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LONELY_NGA'), false)
				pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMPLETE_NGA'), true)
	if pCaster.getUnitType() == iBanung:
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if (pCaster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iNga):
				pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LONELY_BANUNG'), false)
				pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMPLETE_BANUNG'), true)

def checkIsLonely(pCaster):
	pPlot = pCaster.plot()
	iBanung = gc.getInfoTypeForString('UNIT_BANUNG_THE_BLIND')
	iNga = gc.getInfoTypeForString('UNIT_NGA_EYE_EATER')
	bLonely = true
	if pCaster.getUnitType() == iNga:
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if (pCaster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iBanung):
				bLonely = false
		if bLonely == true:
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LONELY_NGA'), true)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMPLETE_NGA'), false)
	if pCaster.getUnitType() == iBanung:
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if (pCaster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iNga):
				bLonely = false
		if bLonely == true:
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LONELY_BANUNG'), true)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMPLETE_BANUNG'), false)

##
# II. Hunting mechanics
#-- The Gnolls are capable of gathering food stock after battle. Then they can use the stock in cities, this is
#----- what those functions are for.
#-a.- reqStockFood() checks if the unit is able to give food to the city
#-b.- spellStockFood() actually gives food to the city. The amount depends on the stock the unit is carrying and
#----- on its promotions.
#-c.- reqBanquet() checks if the unit has enough stock to throw a banquet in the city.
#-d.- spellBanquet() actually throws it. It determines the amount of culture generated function of the unit's proms.
##
def reqStockFood(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	p1Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_1')
	p2Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_2')
	p3Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_3')
	if pCity.getOwner() == pCaster.getOwner():
		if pCaster.isHasPromotion(p1Food) or pCaster.isHasPromotion(p2Food) or pCaster.isHasPromotion(p3Food):
			return true
	return false

def spellStockFood(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	p1Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_1')
	p2Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_2')
	p3Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_3')
	pConservation = gc.getInfoTypeForString('PROMOTION_CONSERVATION_ARTS')
	pFoodEquipment = gc.getInfoTypeForString('PROMOTION_FOOD_EQUIPMENT')
	pGenerous = gc.getInfoTypeForString('PROMOTION_GENEROUS')
	pNoFood = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_EMPTY')
	sUnit = pCaster.getName()
	sCity = pCity.getName()
	if pCaster.isHasPromotion(p3Food):
		iFood = 15
		pCaster.setHasPromotion(p3Food, false)
		pCaster.setHasPromotion(pNoFood, true)
	if pCaster.isHasPromotion(p2Food):
		iFood = 10
		pCaster.setHasPromotion(p2Food, false)
		pCaster.setHasPromotion(pNoFood, true)
	if pCaster.isHasPromotion(p1Food):
		iFood = 5
		pCaster.setHasPromotion(p1Food, false)
		pCaster.setHasPromotion(pNoFood, true)
	if pCaster.isHasPromotion(pConservation):
		iFood = iFood * 1.5
	if pCaster.isHasPromotion(pFoodEquipment):
		iFood += CyGame().getSorenRandNum(20, "Food") #Food equipment *can* give a bonus but may not
	if pCaster.isHasPromotion(pGenerous):
		pCaster.setHasPromotion(pGenerous, false)
		CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_NOT_GENEROUS_ANYMORE",(sUnit, sCity)),'',1,gc.getUnitInfo(pCaster.getUnitType()).getButton(),ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
	iFood = iFood + CyGame().getSorenRandNum(5, "Dice") #To randomize the food input
	pCity.changeFood(iFood)
	CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FOOD_STOCKED",(sUnit, iFood, sCity)),'',1,gc.getUnitInfo(pCaster.getUnitType()).getButton(),ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
	
def reqBanquet(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	p2Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_2')
	p3Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_3')
	if pCity.getOwner() == pCaster.getOwner():
		if pCaster.isHasPromotion(p2Food) or pCaster.isHasPromotion(p3Food): #can't be cast with just p1Food
			return true
	return false

def spellBanquet(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = pCaster.getOwner()
	p2Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_2')
	p3Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_3')
	pGenerous = gc.getInfoTypeForString('PROMOTION_GENEROUS')
	pNoFood = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_EMPTY')
	sUnit = pCaster.getName()
	sCity = pCity.getName()
	if pCaster.isHasPromotion(p2Food):
		iCulture = 10
		pCaster.setHasPromotion(p2Food, false)
		pCaster.setHasPromotion(pNoFood, true)
	if pCaster.isHasPromotion(p3Food):
		iCulture = 20
		pCaster.setHasPromotion(p3Food, false)
		pCaster.setHasPromotion(pNoFood, true)
	if pCaster.isHasPromotion(pGenerous):
		iCulture = int(iCulture * 1.5)
	if not pCaster.isHasPromotion(pGenerous):
		iChance = iCulture * 2 #the more culture the unit gives, the higher its chance to get Generous
		if iChance > CyGame().getSorenRandNum(100, "Generous"): #Generous is not always applied
			pCaster.setHasPromotion(pGenerous, true)
			CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_YOU_ARE_GENEROUS",(sUnit, sCity)),'',1,gc.getUnitInfo(pCaster.getUnitType()).getButton(),ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
	iCulture = iCulture + CyGame().getSorenRandNum(5, "Feast") #To randomize a bit the input of culture
	pCity.changeCulture(iPlayer, iCulture, true)
	CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_BANQUET",(sUnit, iCulture, sCity)),'',1,gc.getUnitInfo(pCaster.getUnitType()).getButton(),ColorTypes(8),pCity.getX(),pCity.getY(),True,True)

def spellLoadFood(pCaster):
	pCity = pCaster.plot().getPlotCity()
	iRnd = CyGame().getSorenRandNum(100, "Loading")
	if iRnd < 50: #50% chance of getting the smaller load
		pCaster.setHasPromotion(gc.getInfoTypeForString("PROMOTION_FOOD_LOAD_1"), true)
		pCity.changeFood(-15)
	elif iRnd >= 50 and iRnd < 80: #30% chance of getting a bigger load
		pCaster.setHasPromotion(gc.getInfoTypeForString("PROMOTION_FOOD_LOAD_2"), true)
		pCity.changeFood(-30)
	elif iRnd >= 80: #20% chance of getting the biggest load
		pCaster.setHasPromotion(gc.getInfoTypeForString("PROMOTION_FOOD_LOAD_3"), true)
		pCity.changeFood(-45)
		
def spellUnloadFood(pCaster):
	pCity = pCaster.plot().getPlotCity()
	if pCaster.isHasPromotion(gc.getInfoTypeForString("PROMOTION_FOOD_LOAD_3")):
		pCity.changeFood(+45)
	if pCaster.isHasPromotion(gc.getInfoTypeForString("PROMOTION_FOOD_LOAD_2")):
		pCity.changeFood(+30)
	else:
		pCity.changeFood(+15)
	
##
# III. World spell
#-a.- The function doesn't seem to do anything: it's in fact a trigger function, triggering the spell effects when a
#----- unit lose a fight.
##
def reqEdgeOfExtinction(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		return False
	return True

def spellEdgeOfExtinction(caster):
	iTurn = int(CyGame().getGameTurn())
	iTurn += 1
	gc.getGame().changeScenarioCounter(iTurn)

##
# IV. Shur reqs and spells
#-- The Shur spells are unique spells only available to the Shur, Heishur and Heheishur units. They basically work
#----- like standard spells.
#-a.- reqMagneticSurge() checks if there's actually an enemy in range.
#-b.- spellMagneticSurge() checks how much damage it will do and which stack it will hurt. For damage, metal weapons
#----- proms are checked and each increase the total damage input.
#-c.- spellImagesOfRemorse() grants the Remorse promotions to range+1 enemy units. It has 10% chance of granting Guilt
#----- instead, which is less likely to wear off.
#-d.- reqSpiritTwisting() checks if the caster has already casted and if it's not under the effect of counter-twisting
#----- proms like Twisted and Broken.
#-e.- spellSpiritTwisting() allows the caster to recast at the cost of losing its mind. The chance of side-effects are
#----- in there.
#-f.- reqUnseenHaven() is checking for features allowing the spell to be used.
#-g.- spellUnseenHaven() blocks any unit not the caster's level to enter the tile. The caster is then held.
#-h.- spellExitHaven() allows the caster to move again but removes the level restriction on the tile.
#-i.- reqEndless() checks if any unit in the caster stack has less than 50% health.
#-j.- spellEndless() restore all health of units with <50% health. They're allowed one fight and, then, lose 90% of their
#----- health. Maybe the spell should be renamed.
#-k.- spellGreenBoom() is a monster. With it, you can kill anything at range+2 since it doesn't have damage cap. This
#----- can be changed here. I plan on adding a "repel-hell" effect.
##
def reqMagneticSurge(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner()) 
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			bEnemy = false
			bNeutral = false
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					bEnemy = true
				else:
					bNeutral = true
			if (bEnemy and bNeutral == false):
				return true
	return false

def spellMagneticSurge(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iBestValue = 0
	pBestPlot = -1
	iEnchantedBlade = gc.getInfoTypeForString('PROMOTION_ENCHANTED_BLADE')
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	iOrthusAxe = gc.getInfoTypeForString('PROMOTION_ORTHUS_AXE')
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			bNeutral = false
			iValue = 0
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if eTeam.isAtWar(pUnit.getTeam()):
					iValue += 5 * pUnit.baseCombatStr()
				else:
					bNeutral = true
			if (iValue > iBestValue and bNeutral == false):
				iBestValue = iValue
				pBestPlot = pPlot
	if pBestPlot != -1:
		iDamage = 10
		iStep = 20
		for i in range(pBestPlot.getNumUnits()):
			pUnit = pBestPlot.getUnit(i)
			if pUnit.isHasPromotion(iEnchantedBlade):
				iStep = 25
			if pUnit.isHasPromotion(iBronze):
				iDamage += iStep
			if pUnit.isHasPromotion(iIron):
				iDamage += iStep
			if pUnit.isHasPromotion(iMithril):
				iDamage += iStep
			if pUnit.isHasPromotion(iOrthusAxe):
				iDamage += iStep
			pUnit.doDamage(iDamage, 75, caster, gc.getInfoTypeForString('DAMAGE_PHYSICAL'), true)
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SLOW'),pBestPlot.getPoint())
		
def spellImagesOfRemorse(caster):
	pPlayer = gc.getPlayer(caster.getOwner()) 
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range (iX-1, iX+2, 1):
		for iiY in range (iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				iRnd = CyGame().getSorenRandNum(100, "Guilty!")
				if iRnd < 10:
					if not pUnit.getTeam() == eTeam:
						if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_REMORSE')):
							pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REMORSE'), false)
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GUILT'), true)
					
def reqSpiritTwisting(caster):
	pTwisted = gc.getInfoTypeForString('PROMOTION_TWISTED_SPIRIT')
	pBroken = gc.getInfoTypeForString('PROMOTION_BROKEN_SPIRIT')
	if caster.isHasCasted() and not caster.isHasPromotion(pTwisted) and not caster.isHasPromotion(pBroken):
		return true
	return false

def spellSpiritTwisting(caster):
	pTwisted = gc.getInfoTypeForString('PROMOTION_TWISTED_SPIRIT')
	pMindwrecked = gc.getInfoTypeForString('PROMOTION_MINDWRECKED')
	pBroken = gc.getInfoTypeForString('PROMOTION_BROKEN_SPIRIT')
	pAscended = gc.getInfoTypeForString('PROMOTION_ASCENDED_SPIRIT')
	iRnd = CyGame().getSorenRandNum(100, "Spirit Twisting")
	if caster.isHasPromotion(pAscended):
		caster.setHasCasted(false)
	elif iRnd > 35:
		caster.setHasCasted(false)
		iRnd2 = CyGame().getSorenRandNum(100, "Side effects of twisting")
		if iRnd2 > 70:
			caster.setHasPromotion(pMindwrecked, true)
		if iRnd2 > 95: #Both would be acquired
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), true)
	iRnd3 = CyGame().getSorenRandNum(100, "Super side effects")
	if not caster.isHasPromotion(pAscended): #Can't acquire both at the same time
		if iRnd3 == 99:
			caster.setHasPromotion(pAscended, true)
		if iRnd3 <= 10:
			caster.setHasPromotion(pBroken, true)
			
def reqUnseenHaven(caster):
	pPlot = caster.plot()
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iNewForest = gc.getInfoTypeForString('FEATURE_FOREST_NEW')
	iAncientForest = gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')
	iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
	if pPlot.getFeatureType() == iForest or pPlot.getFeatureType() == iNewForest or pPlot.getFeatureType() == iAncientForest or pPlot.getFeatureType() == iJungle or pPlot.isHills():
		if caster.getLevel() > 0:
			if not caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IN_UNSEEN_HAVEN')):
				return true
	return false

def spellUnseenHaven(caster):
	pPlot = caster.plot()
	iLevel = caster.getLevel()
	pPlot.setMinLevel(iLevel)
	
def spellExitHaven(caster):
	pPlot = caster.plot()
	pPlot.setMinLevel(0)
	
def reqEndless(caster):
	pPlot = caster.plot()
	iValue = 0
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getDamage() > 50:
			iValue += 1
	if iValue > 0:
		return true
	return false

def spellEndless(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getDamage() > 50:
			pUnit.setDamage(0, caster.getOwner())
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENDLESS'), true)
			
			
def spellGreenBoom(caster):
	iX = caster.getX()
	iY = caster.getY()
	sUnit = caster.getName()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			iImprovement = pPlot.getImprovementType()
			if iImprovement != -1:
				if not gc.getImprovementInfo(iImprovement).isPermanent():
					iRnd = CyGame().getSorenRandNum(100, "Destroying improvements")
					if iRnd >= 25:
						sImprovement = gc.getImprovementInfo(iImprovement).getDescription()
						pPlot.setImprovementType(-1)
						CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GREEN_BOOM_IMPROVEMENT_DESTROYED",(sUnit, sImprovement)),'',1,gc.getImprovementInfo(iImprovement).getButton(),ColorTypes(7),iiX,iiY,True,True)
			#if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_HELL'):
			#	pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)

##
# V. Kha abilities
#-- The Kha is a unique unit for the Ngomele. It is a troup of actors, dancers and singers. They have unique abilities
#----- unfound anywhere else in the game. They are capable of singing songs (basically buffing the stack), refrains
#----- (which add powerful bonus to the city or the plot but force the singer to keep singing every turn, not moving),
#----- playing plays (either Great Plays, one-shot super-powerful plays, or Plays, costing gold and increasing turn
#----- output of the city) and telling tales (giving a one-shot culture bonus to a city depending on many factors).
##
### 1. Recordbook mechanics
##-- Those functions are there to manage the songs & plays a Kha knows.
##----- Their particularity is that they use getPromotionPrereqAnd() and check if it's PROMOTION_BLANK_PAGE to see if
##----- the promotion is a song, a play or whatever ability of the Kha. This is how I designed it: a simple, repeatable
##----- and XML way of telling: "This is a Kha ability".
##-a.- reqGetBlankPage() simply checks if the caster can acquire a new Blank Page.
##-b.- reqChangeRecordbook() checks if the caster can change its spellbook. It can if it already has at least one
##----- Kha ability.
##-c.- spellChangeRecordbook() removes all promotions that enable Kha abilities.
def reqGetBlankPage(caster):
	iPage = gc.getInfoTypeForString('PROMOTION_BLANK_PAGE')
	iFilledSlots = 0
	if caster.isHasPromotion(iPage):
		return false
	for iProm in range(gc.getNumPromotionInfos()):
		if gc.getPromotionInfo(iProm).getPromotionPrereqAnd() == iPage:
			if caster.isHasPromotion(iProm):
				iFilledSlots += 1
	iLevel = caster.getLevel()
	iBlankSlots = iLevel - iFilledSlots
	if iBlankSlots > 0:
		return true
	return false

def reqChangeRecordbook(caster):
	iCount = 0
	for iProm in range(gc.getNumPromotionInfos()):
		if gc.getPromotionInfo(iProm).getPromotionPrereqAnd() == gc.getInfoTypeForString('PROMOTION_BLANK_PAGE'):
			if caster.isHasPromotion(iProm):
				iCount += 1
	if iCount > 0:
		return true
	return false

def spellChangeRecordbook(caster):
	for iProm in range(gc.getNumPromotionInfos()):
		if gc.getPromotionInfo(iProm).getPromotionPrereqAnd() == gc.getInfoTypeForString('PROMOTION_BLANK_PAGE'):
			if caster.isHasPromotion(iProm):
				caster.setHasPromotion(iProm, false)

##
### 2. Held refrains mechanics
##-- Those functions help doing the Held Refrain mechanic which forces a Kha to keep singing every turn until the player
##----- choses to stop.
##-a.- reqIsNotSinging() specifies the requirements for a Kha to be able to perform a Refrain.
##-b.- reqIsNotSingingWhispers() is a special version of -a.-: it is used for the Whispers refrain in order to disallow
##----- two Kha the ability of singing both Whispers on the same tile, which would result in cumulated bonus.
##-c.- isSinging() prevents the Kha from casting by forcing HasCasted status on it.
##-d.- isSingingEyesOfTheSea() is a special version of -c.-: it applies the effect of the Refrain every turn, unlike
##----- other refrains which allow the effect to remain active. May be changed in the future.
##-e.- reqStopSinging() just checks if the Kha is currently singing.
##-f.- spellStopSinging() removes the Is Singing promotion, breaking the isSinging() promotion from being triggered.
##----- Thus, the Kha is able to move again.
##
def reqIsNotSinging(caster):
	lSongs = []
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_MELODIES_OF_LIFE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_THE_IMPREGNABLE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_EYES_OF_THE_SEA'))
	iValue = 0
	for i in range(len(lSongs)):
		if caster.isHasPromotion(lSongs[i]):
			iValue += 1
	if iValue == 0:
		return true
	return false

def reqIsNotSingingWhispers(caster):
	lSongs = []
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_MELODIES_OF_LIFE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_THE_IMPREGNABLE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_EYES_OF_THE_SEA'))
	iValue = 0
	for iUnit in range(caster.plot().getNumUnits()):
		pUnit = caster.plot().getUnit(iUnit)
		if not pUnit.isHasPromotion(lSongs[1]):
			for i in range(len(lSongs)):
				if caster.isHasPromotion(lSongs[i]):
					iValue += 1
		else:
			iValue += 1
	if iValue == 0:
		return true
	return false

def isSinging(caster):
	caster.setHasCasted(true)
	
def isSingingEyesOfTheSea(caster):
	iEyes = gc.getInfoTypeForString('PROMOTION_SEASEEING')
	for iUnit in range(caster.plot().getNumUnits()):
		pUnit = caster.plot().getUnit(iUnit)
		if not pUnit.isHasPromotion(iEyes):
			pUnit.setHasPromotion(iEyes, true)
	caster.setHasCasted(true)

def reqStopSinging(caster):
	lSongs = []
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_MELODIES_OF_LIFE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_THE_IMPREGNABLE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_EYES_OF_THE_SEA'))
	iValue = 0
	for i in range(len(lSongs)):
		if caster.isHasPromotion(lSongs[i]):
			iValue += 1
	if iValue > 0:
		return true
	return false

def spellStopSinging(caster):
	pPlot = caster.plot()
	lSongs = []
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_MELODIES_OF_LIFE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_THE_IMPREGNABLE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_EYES_OF_THE_SEA'))
	for i in range(len(lSongs)):
		if caster.isHasPromotion(lSongs[i]):
			caster.setHasPromotion(lSongs[i], false)
			if lSongs[i] == gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'):
				gc.getGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), YieldTypes.YIELD_PRODUCTION, -1)
				gc.getGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), YieldTypes.YIELD_COMMERCE, -1)

##
### 3. Songs & refrains
##-- Those functions are one-shot songs.
##-a.- spellHymnOfTheDefeated() has 5% chance per level of the Kha to inflict Terrified to surrounding enemy units.
##-b.- spellFieryWangole() has 10% chance of inflicting Enraged to Tier 1 units.
##-c.- reqBalladOfThePinkTongue() checks if the Kha isn't singing (it's a [V.2.c] special case) and if the city it's
##----- in is currently in anger mode.
##-d.- spellBalladOfThePinkTongue() ends the anger mode.
##-e.- misBalladOfThePinkTongue() is the result of a miscast of [V.3.d]: it lengthens the anger mode.
##-f.- spellWhispers() adds 1P,1C to a pasture tile.
##-g.- spellTheImpregnable() adds the Impregnable promotion to the units in the caster's stack. It's not doable in XML
##----- because the XML adds the Is Singing promotion to the caster.
##-h.- spellWangoleOfBwoheshegu() is my favourite function. I think it's intelligent but this isn't point, is it?
##----- It gives a Motivated promotion each 4 level of the caster. These proms are stackable and give strength modifier
##----- bonus: 10, 25, 45, 70, 100.
##-i.- spellEyesOfTheSea() adds a promotion to the units in the caster's stack. It's done in python for the same reasons
##----- [V.3.g] is.
##
def spellHymnOfTheDefeated(caster):
	iLevel = caster.getLevel()
	iStepChance = 5
	iChance = iLevel * iStepChance
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			for iUnit in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(iUnit)
				if CyGame().getSorenRandNum(100, "Terrified") < iChance:
					if not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_TERRIFIED')):
						pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_TERRIFIED'), true)

def spellFieryWangole(caster):
	pPlot = caster.plot()
	iChance = CyGame().getSorenRandNum(100, "Tier 1 are weak!")
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if gc.getUnitInfo(pUnit.getUnitType()).getTier() == 1:
			if iChance < 10:
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), true)
				
def reqBalladOfThePinkTongue(caster):
	lSongs = []
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_MELODIES_OF_LIFE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_WHISPERS'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_THE_IMPREGNABLE'))
	lSongs.append(gc.getInfoTypeForString('PROMOTION_IS_SINGING_EYES_OF_THE_SEA'))
	iValue = 0
	for i in range(len(lSongs)):
		if caster.isHasPromotion(lSongs[i]):
			iValue += 1
	if iValue > 0:
		return false
	pPlot = caster.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getOccupationTimer > 0:
			return true
	return false

def spellBalladOfThePinkTongue(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setOccupationTimer(0)
	
def misBalladOfThePinkTongue(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.changeOccupationTimer(5)

def spellWhispers(caster):
	pPlot = caster.plot()
	gc.getGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), YieldTypes.YIELD_PRODUCTION, 1)
	gc.getGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), YieldTypes.YIELD_COMMERCE, 1)
	
def spellTheImpregnable(caster):
	pPlot = caster.plot()
	for iUnit in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(iUnit)
		pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMPREGNABLE'), true)
		
def spellWangoleOfBwoheshegu(caster):
	pPlot = caster.plot()
	#fLevel = float(caster.getLevel())
	#fValue = math.ceil(fLevel / 4)
	#iValue = int(fValue)
	iValue = (caster.getLevel()+3) / 4
	CvUtil.pyPrint('Value = %d'
		       %(iValue))
	for iUnit in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(iUnit)
		for i in range(iValue):
			iSfx = str(int(i) + 1)
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MOTIVATED' + iSfx), true)
	

def spellEyesOfTheSea(caster):
	iEyes = gc.getInfoTypeForString('PROMOTION_SEASEEING')
	for iUnit in range(caster.plot().getNumUnits()):
		pUnit = caster.plot().getUnit(iUnit)
		pUnit.setHasPromotion(iEyes, true)

##
### 4. Tales
##-- The Tales are about national myths transmitted by the bards of the Ngomele. Here, the functions determines how much
##----- culture will be added to a city.
##-a.- reqTales() checks if the building Tales isn't present in the city in order to perform a tale. Without it, Tales
##----- would be repeatable and, thus, scary, as they can give a HUGE bonus later on.
##-b.- spellTales() is the actual function determining the amount of culture added to the city.
##
def reqTales(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_TALES')) == 0:
		return true
	return false

def spellTales(caster):
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	py = PyPlayer(iPlayer)
	iOrthusAxe = gc.getInfoTypeForString('PROMOTION_ORTHUSS_AXE')
	aHeroic = []
	iHeroicAtk1 = gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH')
	aHeroic.append(iHeroicAtk1)
	iHeroicAtk2 = gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2')
	aHeroic.append(iHeroicAtk2)
	iHeroicDfs1 = gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE')
	aHeroic.append(iHeroicDfs1)
	iHeroicDfs2 = gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2')
	aHeroic.append(iHeroicDfs2)
	iHero = gc.getInfoTypeForString('PROMOTION_HERO')
	iAdventurer = gc.getInfoTypeForString('PROMOTION_ADVENTURER')
	iDruidic = gc.getInfoTypeForString('PROMOTION_DRUIDIC')
	iValue = 10
	for pUnit in py.getUnitList():
		iLevel = pUnit.getLevel()
		if iLevel >= 15:
			iValue += 10
			CvUtil.pyPrint('Level 15! Value is %d'
				       %(iValue))
		elif iLevel >= 10:
			iValue += 5
			CvUtil.pyPrint('Level 10! Value is %d'
				       %(iValue))
		elif iLevel >= 5:
			iValue += 2
			CvUtil.pyPrint('Level 5! Value is %d'
				       %(iValue))
		if pUnit.isHasPromotion(iOrthusAxe):
			iValue += 10
			CvUtil.pyPrint('Orthus Axe! Value is %d'
				       %(iValue))
		for i in range(len(aHeroic)):
			if pUnit.isHasPromotion(aHeroic[i]):
				iValue += 5
				CvUtil.pyPrint('Heroic! Value is %d'
					%(iValue))
		if pUnit.isHasPromotion(iHero):
			iValue += 15
			CvUtil.pyPrint('Hero! Value is %d'
				       %(iValue))
		if pUnit.isHasPromotion(iAdventurer):
			iValue += 5
			CvUtil.pyPrint('Adventurer! Value is %d'
				       %(iValue))
		if pUnit.isHasPromotion(iDruidic):
			iValue += 7
			CvUtil.pyPrint('Druidic! Value is %d'
				       %(iValue))
	iModifier = 1
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_THEATRE')) > 0:
		iModifier += 0.5
		CvUtil.pyPrint('Theatre! Value is %d'
				       %(iModifier))
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_THEATRE_OF_DREAMS')) > 0:
		iModifier += 1
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_SHURMBUMGWU')) > 0:
		iModifier += 0.5
	if pCity.isHasCorporation(gc.getInfoTypeForString('CORPORATION_ACTORS')):
		iModifier += 0.3
	iValue = iValue * iModifier
	CvUtil.pyPrint('*Modifier! Value is %d'
				       %(iValue))
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
		iValue = int(iValue / 3 * 2)
		CvUtil.pyPrint('Quick! Value is %d'
				       %(iValue))
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
		iValue = int(iValue * 3 / 2)
		CvUtil.pyPrint('Epic! Value is %d'
				       %(iValue))
	if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
		iValue = int(iValue * 3)
		CvUtil.pyPrint('Marathon! Value is %d'
				       %(iValue))
	pCity.changeCulture(iPlayer, iValue, True)
	sCity = pCity.getName()
	CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TALES",(iValue, sCity)),'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/Buildings/Smokehouse.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
# NGOMELE END

### Bandeirante

##### Req: follow Slavery civic; having Bandeirante trait

def reqPutInTrade(pCaster):
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	
	if not pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_BANDEIRANTE')):
		return False
	
	if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_LABOR')) != gc.getInfoTypeForString('CIVIC_SLAVERY'):
		return False
	
	return True

def spellPutInTrade(pCaster):
	pCity = pCaster.plot().getPlotCity()
	
	pCity.changeFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_SLAVE'), 1)
	

###### Forced Labour

def reqPutInForcedLabour(pCaster):
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	
	if not pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_BANDEIRANTE')):
		return False
	
	if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_LABOR')) != gc.getInfoTypeForString('CIVIC_SLAVERY'):
		return False
	
	if not pCaster.isCargo():
		return False
	
	if pCaster.isCargo():
		if pCaster.getTransportUnit().isHasPromotion(gc.getInfoTypeForString('PROMOTION_FORCED_LABOUR2')):
			return False
	
	return True

def spellPutInForcedLabour(pCaster):
	pCargo = pCaster.getTransportUnit()
	
	iForcedLabour1 = gc.getInfoTypeForString('PROMOTION_FORCED_LABOUR1')
	iForcedLabour2 = gc.getInfoTypeForString('PROMOTION_FORCED_LABOUR2')
	
	if pCargo.isHasPromotion(iForcedLabour1):
		pCargo.setHasPromotion(iForcedLabour2, True)
		pCargo.setHasPromotion(iForcedLabour1, False)
	else:
		pCargo.setHasPromotion(iForcedLabour1, True)